In Cpp, Sum Of All Integers In Vector

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
        vector<int> intList;
        intList = {2, 4, 6, 8, 10, 12, 14, 16};
        int result;
        result = accumulate(intList.begin(), intList.end(), 0);
        cout << "result: " << result << endl;
        return 0;
}

Comments

Popular posts from this blog