accumulate( ) computes a summation of all of the elements within a specified range and returns the result.
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main()
{
vector<int> v(5);
int i, total;
for(i=0; i<5; i++) v[i] = i;
total = accumulate(v.begin(), v.end(), 0);
cout << total;
return 0;
}
Related examples in the same category