Answers for "how to get the sum of an int vector in c++"

2

sum of vector c++

#include <numeric>

sum_of_elems = std::accumulate(vector.begin(), vector.end(), 0);
Posted by: Guest on August-29-2021
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

Code answers related to "how to get the sum of an int vector in c++"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language