Skip to content

Commit

Permalink
Merge pull request #179 from Lucifer0420/patch-3
Browse files Browse the repository at this point in the history
 Program to find sum of array
  • Loading branch information
Graey authored Oct 5, 2021
2 parents 277772d + ef78897 commit cfe3568
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions arraysum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Python 3 code to find sum
# of elements in given array
def _sum(arr):

# initialize a variable
# to store the sum
# while iterating through
# the array later
sum=0

# iterate through the array
# and add each element to the sum variable
# one at a time
for i in arr:
sum = sum + i

return(sum)

# driver function
arr=[]
# input values to list
arr = [12, 3, 4, 15]

# calculating length of array
n = len(arr)

ans = _sum(arr)

# display sum
print ('Sum of the array is ', ans)

0 comments on commit cfe3568

Please sign in to comment.