// Thu, Jan 29th, 2026

search notifications

Recursive Minds

Learn. Share. Recurse.

DATA_STRUCTURES_AND_ALGORITHMS

Reverse Number Pattern

šŸ“… April 2, 2023 āœļø Amit Kumar šŸ’¬ 3 Comments ā±ļø 1 min read

In this article, we will learn how to print Reverse Number Pattern

Input: N=4

Output:Ā 

1

2 1

3 2 1

4 3 2 1

JavaScript Solution:

function printPattern(n) {
    for (let i = 1; i <= n; i++) {
        let str = "";
        for (let j = i; j >= 1; j--) {
            str += j;
        }
        console.log(str);
    }
}

 

Java Solution:

import java.util.Scanner;
public class Main
{
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = i; j >= 1; j--) {
                System.out.print(j);
            }
            System.out.println();
        }
    }
}

 

C++ Solution:

#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j >= 1; j--) {
            cout << j;
        }
        cout << endl;
    }
    return 0;
}

 

Python Solution:

for i in range(1, n+1):
    for j in range(i, 0, -1):
        print(j, end="")
    print()

Time Complexity:Ā  O(n*n)

Space Complexity: O(1)

 

To Practice this Question on GFG

Click here

 

Other Questions on patterns:

Program to print square patternĀ 

Program to print right angle triangle star patternĀ 

Program to print right angle triangle numberĀ 

Print inverted right angle triangle star pattern

 

← Previous Async/await in JavaScript Next → Exploring Game Development

// 3 Comments

  1. @Short Hairstyles 2 years ago

    I enjoyed reading your piece and it provided me with a lot of value.

  2. @Long Hairstyles 2 years ago

    Thank you for your post. I really enjoyed reading it, especially because it addressed my issue. It helped me a lot and I hope it will also help others.

  3. @Hairstyles 2 years ago

    Great content! Super high-quality! Keep it up!

Leave a comment