#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void show(int i) {
cout << i << endl;
}
// A running sum.
int summation(int i) {
static int sum = 0;
sum += i;
return sum;
}
int main()
{
vector<int> v;
int i;
for(i=1; i < 11; i++) v.push_back(i);
for_each(v.begin(), v.end(), show);
for_each(v.begin(), v.end(), summation);
cout << summation(0);
return 0;
}
|