Use accumulate to calculate sum for double array with 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