c++11 lambda 我想求10个随机数的平方和 中间那一点不会写的 怎么写呢
#include <bits/stdc++.h>
using namespace std;
void myPrintf(int val)
{
cout << val << " ";
}
int main()
{
int a[24];
vector<int> sourceVector;
sourceVector.resize(10);
srand((unsigned)time(NULL));
for(int i=0;i<10;i++)
{
a[i]=rand()%100;
sourceVector.push_back(a[i]);
}
// int res=0;
// generate(sourceVector.begin(), sourceVector.end(), [&res](int x) {
// res=x*x;
// return res;
// });
for_each(sourceVector.begin(), sourceVector.end(), myPrintf);
cout << endl;
}