sum vector c++
vector<int> v{1,2,3,4,5,6,7,8,9}; int sum = 0; //Method 1: sum = accumulate(v.begin(), v.end(), 0); //Method 2: for(auto& i : v) sum+=i;
sum of vector c++
#include <numeric> sum_of_elems = std::accumulate(vector.begin(), vector.end(), 0);
Source: stackoverflow.com
sum elements in vector c++
for (auto& n : vector) sum_of_elems += n;
Source: stackoverflow.com
C++ find sum of vector
#include<iostream> #include<vector> #include<numeric> using namespace std; int main() { vector<int> v = {2,7,6,10}; cout<<"Sum of all the elements are:"<<endl; cout<<accumulate(v.begin(),v.end(),0); }
Source: www.tutorialspoint.com