Skip to main content

Print numbers from 1 to n using recursion

Printing numbers from 1 to n using recursion means writing a program or function that uses a recursive approach to print all the integers from 1 to n.

Given a positive number N, Our goal is to print number from 1...N without using any loops. So we can use recursion to solve this problem. Because loop are not allowed.

 Example N = 10
 (1 to 10) :  1 2 3 4 5 6 7 8 9 10
Example N = 20
 (1 to 20) :  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Programming Solution

Recursion is a technique in programming where a function calls itself repeatedly until a specific condition is met. In this case, the function would call itself with decreasing values of n until it reaches 1, printing each value as it goes.





Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment