 ### Python Program to Find the Sum of Elements in a List Recursively

#Python Program to Find the Sum of Elements in a List Recursively """for calculating sum of a list recursively we need to call sum method recursively for that purpose we need to check for every element so time complexity for that algorithm is O(n) where 'n' is the size of the list Recursive call of sum function"""
#Program: def sum(arr, size): if(size == 0): return 0 else: return sum(arr, size-1) + arr[size-1] def main(): #Create a list list = [] #Taking maximum size of the list n = int(input("Enter the number of elements of the list: ")) print("Enter the element of the list: ") for i in range(0, n): t = int(input("")) list.append(t) #print the list print("Created list is: ") print(list) b = sum(list, i+1) print("Sum of the list is: ") print(b) main() """ Sample input: Enter the number of elements of the list: 7 Enter the element of the list: 5 8 9 15 6 12 3 Sample output: Created list is: [5, 8, 9, 15, 6, 12, 3] Sum of the list is: 58
""" #### More Articles of CHANDAN BISWAS:

Name Views Likes
Python Program to Find the Sum of Elements in a List Recursively 216 16
C++ program to find minimum in binary tree 224 12