Write a program using recursion to calculate the sum of first n natural nos
Answers
Answered by
0
Answer:
Explanation:
# Python code to find sum
# of natural numbers upto
# n using recursion
# Returns sum of first
# n natural numbers
def recurSum(n):
if n <= 1:
return n
return n + recurSum(n - 1)
# Driver code
n = 5
print(recurSum(n))
Similar questions
English,
6 months ago
English,
6 months ago
Social Sciences,
6 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago
Math,
1 year ago
Chemistry,
1 year ago