Reverse number patternIn this article you will learn about how to print reverse number pattern

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

 

3 thoughts on “Reverse Number Pattern”

Leave a Reply

Your email address will not be published. Required fields are marked *