Simple Array Sum

Sort by

recency

|

3474 Discussions

|

  • + 0 comments

    Simple and easy solution for C++

    int simpleArraySum(vector<int> ar) {
        return accumulate(ar.begin(), ar.end(), 0);
    }
    
  • + 0 comments

    For Python3 Platform

    I wrote the code from scratch to get more practice

    def simpleArraySum(arr):
        return sum(arr)
    
    n = int(input())
    arr = list(map(int, input().split()))
    
    result = simpleArraySum(arr)
    
    print(result)
    
  • + 0 comments

    in javascript is more simple :

    function simpleArraySum(ar) { return ar.reduce((arr,cur)=> arr + cur, 0)

    }

  • + 0 comments

    Example input If you want to sum 6 numbers:

    6
    1 2 3 4 5 6
    

    First line 6 → there are 6 integers in the array Second line → the actual numbers

  • + 0 comments

    I’m working on a client’s WordPress website and need some assistance adding this script to one of the pages. Could you guide me on how to integrate it properly?