Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

sum of vector elemnt in c++

#include <bits/stdc++.h>

using namespace std;

int sum(vector a){
  int ans = 0;
  for(int i = 0; i<a.size(); i++){
  	ans+=a[i];
  }
  return ans;
}

int main(){
  vector<int> a = {1, 2, 3, 4, 5, 6};
  cout << sum(a) << endl;output: 21
  return 0;
}
Source by arena.moi #
 
PREVIOUS NEXT
Tagged: #sum #vector #elemnt
ADD COMMENT
Topic
Name
1+7 =