1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
#include <algorithm>
#include <iterator>
template<size_t sz>
int fndsz(const int (&ar)[sz])
{
return sz - std::distance(std::begin(ar), std::find_if(std::begin(ar), std::end(ar), [](auto i) { return i != 0; }));
}
int main()
{
const int no1[20] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8};
const int no2[20] = {1};
std::cout << fndsz(no1) << "\n" << fndsz(no2) << '\n';
}
| |