Numeric Algorithms in C++ STL


header file required for numeric algorithem
#include <numeric>

sum of list of data
init=0
double summation = accumulate (vec.begin(), vec.end(), init);

inner product of two vectors
double ipval = inner_product(vec1.begin(), vec1.end(),vec2.begin(), init)

partial sum of vector
partial_sum(vec.begin(), vec.end(), resultvec.begin());

Compute difference between consequence elements of a vector
adjacent_difference(vec.begin(), vec.end(), resultvec.begin());

No comments:

Post a Comment

would you like it. :)