Python Recursive Function Add Numbers – Write a Python Program to display sum of 1 to 10 numbers using recursion. Call this recursive function in main.
Python Code – Program With Recursive Function Add Numbers
# Write a recursive function to add numbers # from 1 to 10 recursively. Call it from # main function def add_recursive(num): if num==0: return 0 else: # function calls it self again by decrementing number by 1 return num + add_recursive(num - 1) # Call function from main res = add_recursive(10) print("Sum =",res)
Output
Sum = 55
You will also like to study:
Python Recursion With Example Recursive Function
- C Program Sum of One to N by Recursion
- C Program Sum of Digits by Recursion
- C Program Reverse Number by Recursion
- C Program Fibonacci Series by Recursion
- C Program Power By Recursion
- C Program Find Factorial by Recursion
- C Program Quick Sort
- C Program Merge Sort
- Using Recursion in Java Find Factorial of Number
- Recursion in Java Explained With Examples
- Program Factorial by Loop and Recursion Versions