Answers for "sum vector c++"

C++
14

sum of vector c++

accumulate(a.begin(), a.end(), 0);
Posted by: Guest on May-17-2020
1

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;
Posted by: Guest on June-05-2021
0

sum elements in vector c++

for (auto& n : vector)
    sum_of_elems += n;
Posted by: Guest on June-26-2020
0

C++ sum a vector of digits

// Sum digits in vector
int digit_sum(vector<int> num) {
    int sum = 0;
    for (auto x : num) sum += x;
    return sum;
}
Posted by: Guest on April-21-2021

Browse Popular Code Answers by Language