Python Recursive Function Add Numbers

By | December 4, 2022

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 Recursive Function Add Numbers - Recursion in Python

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 

 

 

 151 total views,  1 views today

Leave a Reply

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