Codelet #73


#include <iostream> #include <vector> #include <algorithm> using namespace std; /* Count Number of Zeros */ int main() { //Initialize the vector vector<int> MyVec={ 0, 0, 0, 0 ,0, 3, 2 ,8 ,11 ,10 ,15 ,22}; int count=0; //print out all the elements of the vector for_each(MyVec.begin(),MyVec.end(), [&count](int elem) { if(elem==0) { count++; } }); cout<<"Count of zeroes is "<<count<<endl; return 0; }

Loading Please Wait...