Computer Science, asked by adeogam04, 3 months ago

programs to display the following patterns
(b) 1 2 3 4 5
6 7 8 9
10 11 12
13 14
15

Answers

Answered by anindyaadhikari13
2

Question ?

Display the following pattern.

1 2 3 4 5

6 7 8 9

10 11 12

13 14

15

Program:-

This is written in Java.

import java.util.*;

class Pattern

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the number of rows for the pattern: ");

int a=1;

int n=sc.nextInt();

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

{

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

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

System.out.println();

}

}

}

This is written in Python.

n=int(input("Enter the number of rows for the pattern: "))

a=1

for i in range(n, 0,-1):

for j in range (1,i+1):

print(a, end=" ")

a=a+1

print

Similar questions