Computer Science, asked by MysteryBros94, 5 months ago

write a program to print the following pattern 1
21
321
4321
54321

Answers

Answered by grishmasagar1
1

Answer:

Java Program to print the pattern : 1 21 321 4321 54321

import java.util.Scanner;

public class Pattern

{

public static void main(String[] args)

{

Scanner scanner = new Scanner(System.in);

System.out.print("Enter a number: ");

int n = scanner.nextInt();

for (int i = 1; i <= n; i++)

{

for (int j = i; j >= 1; j--)

{

System.out.print(j + " ");

}

}

}

}

Here is a sample output :

Enter a number: 5

1

2 1

3 2 1

4 3 2 1

5 4 3 2 1

Answered by akashkarsale
0

Explanation:

// This program is in C++

#include<iostream>

using namespace std;

int main()

{

int i = 1;

while(i<=5)

{

for(int j=i; j>=1;j--)

{

cout<<j<<endl;

}

i++;

}

return 0;

}

Similar questions