1//Syntax
2accumulate(first, last, sum);
3accumulate(first, last, sum, myfun);
4
5first, last : first and last elements of range
6 whose elements are to be added
7sum : initial value of the sum
8myfun : a function for performing any
9 specific task. For example, we can
10 find product of elements between
11 first and last.
12//Example
13 int a[] = {5 , 10 , 15} ;
14 int res = accumulate(a,a+3,0); // 30
1 array<int,10> a{1,2,3,4,5,6,7,8,9};
2 int sum = 0;
3//Method 1:
4 sum = accumulatea(a.begin(), a.end(), 0);
5//Method 2:
6 for(auto& i : a) sum+=i;