cpp accumulate code example
Example 1: accumulate c++
#include <numeric>
#include <vector>
using namespace std;
int main()
{
vector<int> nums{1,2,3,4,5};
int sum = 0;
sum = accumulate(nums.begin(), nums.end(), sum);
}
Example 2: accumulate() in c++
accumulate(first, last, sum);
first, last : first and last elements of range
whose elements are to be added
suppose array is 'a'.
sum : initial value of the sum
Eg: int sum=0;
accumulate(a.begin(),a.end(),sum);
Example 3: accumulate in cpp
accumulate(start, end, initial_sum);