Skip to content

Instantly share code, notes, and snippets.

@xbns
Last active December 14, 2020 19:10
Show Gist options
  • Save xbns/142a16a0d3587ac9965543423f2957bc to your computer and use it in GitHub Desktop.
Save xbns/142a16a0d3587ac9965543423f2957bc to your computer and use it in GitHub Desktop.
Problem : Simple Array Sum #hackerrank

Simple Array Sum

Given an array of N integers, can you find the sum of its elements?

Input Format

The first line contains an integer,N ,denoting the size of the array. he second line contains N space-separated integers representing the array's elements.

Output Format

Print the sum of the array's elements as a single integer.

Sample Input

6
1	2	3	4	10 11

Sample Output

31

Explanation

We print the sum of the array's elements,which is: 1+2+3+4+1011=31 .

arr = []
n = 0
def simpleArraySum(ar):
sum = 0;
n = len(ar)
for i in range(n):
sum+=ar[i]
return (sum)
n = int(input().strip())
ar = list(map(int, input().rstrip().split()))
# driver function
# n = 6
#ar = [1,2,3,4,10,11] # expected "31"
result = simpleArraySum(ar)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment