64,683
社区成员
发帖
与我相关
我的任务
分享
// count_if example
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool IsOdd (int i) { return ((i%2)==1); }
int main () {
int mycount;
vector<int> myvector;
for (int i=1; i<10; i++) myvector.push_back(i); // myvector: 1 2 3 4 5 6 7 8 9
mycount = (int) count_if (myvector.begin(), myvector.end(), IsOdd);
cout << "myvector contains " << mycount << " odd values.\n";
return 0;
}
int main(){
const int xmax = 10,ymax = 10;
int arr[xmax][ymax] = {0};
int x = 5,y = 6;
int sum = 0;
for(int i = 0; i < x; i++)
sum = std::accumulate(arr[i],arr[i]+ymax,sum);//计算sum + arr[i][0,1,2,...,ymax]的和。
std::cout<<sum;
system("pause");
return 0;
}