Python program to print all the natural numbers from 1 to N using recursion has been shown here.
Page content(s):
Additional content(s):
1. Python Program & output to Print First N Natural Numbers using recursion
Code has been copied
#********************************************** # alphabetacoder.com # Python program to print all natual numbers # from 1 to n using recursion #*********************************************/ # recursive function def printUptoN(n): #condition for calling if n>1: printUptoN(n-1) print(n, end=" ") # take input of the number upto # which numbers will be printed n=int(input("Enter the upper limit=")) # call the recursive function to # print the natural numbers printUptoN(n)
Output
Case 1:
Enter the upper limit=11
First 11 natural numbers are : 1 2 3 4 5 6 7 8 9 10 11
Case 2:
Enter the upper limit=5
First 5 natural numbers are : 1 2 3 4 5