Answers for "sum array c++"

C++
0

sum array c++

//Syntax
accumulate(first, last, sum);
accumulate(first, last, sum, myfun); 

first, last : first and last elements of range 
              whose elements are to be added
sum :  initial value of the sum
myfun : a function for performing any 
        specific task. For example, we can
        find product of elements between
        first and last.
//Example
  int a[] = {5 , 10 , 15} ;
  int res = accumulate(a,a+3,0); // 30
Posted by: Guest on May-10-2021
0

sum array c++

array<int,10> a{1,2,3,4,5,6,7,8,9};
  int sum = 0;
//Method 1:
  sum = accumulatea(a.begin(), a.end(), 0);
//Method 2: 
  for(auto& i : a) sum+=i;
Posted by: Guest on June-05-2021

Browse Popular Code Answers by Language