Answers for "c++ add everything in a vector"

C++
0

c++ add everything in a vector

#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);
}
/* Output
Sum of all the elements are:
25
*/
Posted by: Guest on February-07-2022

Browse Popular Code Answers by Language