Python Program to find sum of array

Created with Sketch.

Python Program to find sum of array

Given an array of integers, find sum of its elements.

Examples :

Input : arr[] = {1, 2, 3}
Output : 6
1 + 2 + 3 = 6

Input : arr[] = {15, 12, 13, 10}
Output : 50
# Python 3 code to find sum 
# of elements in given array
def _sum(arr,n):
     
    # return sum using sum 
    # inbuilt sum() function
    return(sum(arr))
 
# driver function
arr=[]
# input values to list
arr = [12, 3, 4, 15]
 
# calculating length of array
n = len(arr)
 
ans = _sum(arr,n)
 
# display sum
print (\'Sum of the array is \',ans)
 

Leave a Reply

Your email address will not be published. Required fields are marked *