1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <vector>
#include <iostream>
std::vector<int> secfunc(int* arr, std::size_t SIZE, int values)
{
std::vector<int> indices;
for (int a = 0; a < SIZE; ++a)
if(arr[a] == values)
indices.push_back(a);
return indices;
}
template<typename T, std::size_t N>
std::size_t array_size(T (&array)[N])
{
return N;
}
int main()
{
int numbers[] = {2, 1, 1, 4, 5, 2, 1, 3};
auto ind = secfunc(numbers, array_size(numbers), 1);
if(ind.size() == 0)
std::cout << "No elements equals 1\n";
else {
std::cout << "Indices of elements which equals 1: ";
for(auto i : ind)
std::cout << i << ' ';
}
}
|
Indices of elements which equals 1: 1 2 6 |