Simple Array Sum

Sort by

recency

|

3456 Discussions

|

  • + 0 comments

    This one's for the functional peeps out there:

    from functools import reduce
    
    def simpleArraySum(ar):
        # Write your code here
        return reduce(lambda x, y: x + y, ar)
    
  • + 0 comments

    By the way, I’m not good at simple array sum problem solutions in Python, but when it comes to gaming like Hailey’s Treasure Adventure Apk, I learn quickly and enjoy the process.

  • + 0 comments

    Java 15

    This is my code for Java 15 :-

    public static int simpleArraySum(List<Integer> ar) {
        int sum = 0;
        for(int i: ar) sum+=i;
        return sum;
    }
    
  • + 0 comments

    For Python3 Platform

    with python, you can use the sum function. But with other languages, you have to use the loop to calculate the sum

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

    def simpleArraySum(ar): c = 0 for i in ar:
    c = c + i return c