World Languages, asked by Bhavyasharma9193, 11 months ago

Write a program that reads an input n from stdin. n tells us the number of rows to be printed. Print the pattern as per the given examples. Input format: The first line contains the number of inputs. The lines after that contain a different values for n Example Input: 2 3 5 Output: 1 1 2 1 2 3 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5

Answers

Answered by suriyagokul1221
0

Aoutput

22

333

4444

55555

Explanation:

Answered by qwluton
0

Here's one way you could write a program in Python to print the desired pattern based on the input value of n:

n = int(input()) # number of rows to be printed

for i in range(n):

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

       print(j, end=' ')

   print()

  • You can run this code and check the output for the given examples:

Input:

2

3

5

Output:

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

  • This program takes in an input of n from the user, then uses nested loops to print the desired pattern.
  • The outer loop iterates n times, and for each iteration of the outer loop, the inner loop iterates from 1 to i+1, where i is the current iteration of the outer loop.
  • This inner loop prints the current value of j and a space, which forms the pattern of numbers. At the end of each iteration of the outer loop, a newline is printed to move to the next row.
  • #SPJ3

Similar questions