Check out example codes for "sum of vector c++". It will help you in understanding the concepts better.

Code Example 1

accumulate(a.begin(), a.end(), 0);

Code Example 2

accumulate(a.begin(), a.end(), 0)

Code Example 3

for (auto& n : vector)
    sum_of_elems += n;

Learn ReactJs, React Native from akashmittal.com