Use accumulate() and minus() : accumulate « STL Algorithms Helper « C++






Use accumulate() and minus()

  
#include <iostream>
#include <numeric>
using namespace std;

int main()
{
   double v1[3] = {1.0, 2.2, 4.3}, sum;

   sum = accumulate(v1, v1 + 3, 0.0, minus<int>());
   cout << "sum = " << sum << endl;
}
  
    
  








Related examples in the same category

1.Calculate sum of elements in a vector
2.Algorithm: Use accumulate to calculate product
3.Demonstrating the generic accumulate algorithm with a reverse iterator
4.Illustrating the generic accumulate algorithm with predicate
5.accumulate( ) computes a summation of all of the elements within a specified range and returns the result.
6.Use accumulate to calculate sum for double array with minus()
7.Compute the mean float mean with accumulate function
8.accumulate value in a vector
9.Finding the Mean Value