Simple List Sum | Given a List of integers, find the sum of its elements | Hackerrank
Given an array of integers, find the sum of its elements.
For example, if the array a = [1,2,3,4,5] then return 1+2+3+4+5 i.e 15
This is a problem from hackerrank problem solving section and i have solved it.
HERE IS THE CODE:
# MyProgramArchives # Made by Aditya Shrivastava # Please Solve on your own and try less to search on internet #Initilizing function def simpleArraySum(ar): # sum is set to 0 num = 0 # iterating over the array for i in range(0, len(ar)): # here is the main part. As num was set to 0 # we can start adding the values from the list # if you analyze the code you will find a chain of numbers adding # over each iteration num = num + ar[i] #returnimg the value of num as it will have or final sum return num
I also faced problem, solving this question but at last you get success.
THANK YOU. VISIT AGAIN !!!!
*PLEASE USE FOR EDUCATIONAL PURPOSE ONLY
Aditya Shrivastava | MyProgramArchives
Comments
Post a Comment