Ad
Code
Diff
  • #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 = 0
    • for i in arr:
    • var += i
    • return 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;
    • }