VOOZH about

URL: https://www.geeksforgeeks.org/dsa/print-n-to-1-without-loop/

⇱ Print n to 1 using Recursion - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Print n to 1 using Recursion

Last Updated : 27 Sep, 2025

Given an integer n. Print numbers from n to 1 using recursion.

Examples:

Input: n = 3
Output: [3, 2, 1]
Explanation: Print numbers in reverse order from n down to 1.

Input: n = 10
Output: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Explanation: Print numbers in reverse order from n down to 1.

Approach:

The idea is to use recursion to print numbers in decreasing order. We first check the base case: if n becomes 0, we stop further recursive calls. Otherwise, we first print the current number n and then make a recursive function call with n-1. This way, the function keeps reducing the problem size until it reaches the base case.


Output
3 2 1 

Time Complexity: O(n)
Auxiliary Space: O(n), Recursive Stack Space

Comment
Article Tags:
Article Tags: