Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sum of natural numbers recursion

# Python program to find the sum of natural using recursive function

def recur_sum(n):
   if n <= 1:
       return n
   else:
       return n + recur_sum(n-1)

# change this value for a different result
num = 16

if num < 0:
   print("Enter a positive number")
else:
   print("The sum is",recur_sum(num))


#Output - The sum is 210
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #python #sum #natural #numbers #recursion
ADD COMMENT
Topic
Name
5+3 =