Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Print Number From N to 1

Easy Acceptance 80% Points 20

You are given an integer n. Your task is to print all the numbers starting from n down to 1 using recursion only. You are not allowed to use any loops such as for or while.

All numbers should be printed in decreasing order, on a single line, separated by spaces.

Examples
Example 1

Example 1

Input: n = 7

Output: 7 6 5 4 3 2 1

Explanation: Not Needed

Example 2

Example 2

Input: 5

Output: 5 4 3 2 1

Explanation: Not Needed

Constraints
  • 1<=n<=1000
Topics
Recursion
Companies
Amazon Samsung Paypal
Added 07 Feb 2026 80% acceptance
Ln 1, Col 1Sign in to save your code
3
3 2 1