Answers for "sum in c ++"

10

sum of elements in c++ stl

accumulate(a.begin(), a.end(), 0)
Posted by: Guest on May-17-2020
1

Array sum in c++ stl

// C++ program to demonstrate working of accumulate()
#include <iostream> 
#include <numeric>     
using namespace std;
   
// User defined function that returns sum of
// arr[] using accumulate() library function.
int arraySum(int a[], int n) 
{
    int initial_sum  = 0; 
    return accumulate(a, a+n, initial_sum);
}
   
int main() 
{
    int a[] = {5 , 10 , 15} ;
    int n = sizeof(a)/sizeof(a[0]);
    cout << arraySum(a, n);
    return 0;
}
Posted by: Guest on January-30-2022

Code answers related to "TypeScript"

Browse Popular Code Answers by Language