Python Program to find the sum of n natural numbers using recursion
In this program, you will learn how to find the sum of n natural numbers using recursion in Python.
15 = 1 + 2 + 3 + 4 + 5
Example: How to find the sum of n natural numbers using recursion in Python.
def findsum(n):
if n == 1:
return 1
n = n + findsum(n - 1)
return n
n = int(input("Enter a number:"))
s = findsum(n)
print("Sum is:", s)
Output:
Enter a number:4
Sum is: 10