#include <iostream> #include <vector> using namespace std; int sum(vector<int>& arr) { int i = 0, sum = 0, n = arr.size() - 1; while(i <= n) { sum += arr[i++]; } return sum; }
def sum(arr):var = 0for i in arr:var += ireturn var- #include <iostream>
- #include <vector>
- using namespace std;
- int sum(vector<int>& arr)
- {
- int i = 0, sum = 0, n = arr.size() - 1;
- while(i <= n)
- {
- sum += arr[i++];
- }
- return sum;
- }