Computer Science, asked by agupoochi, 3 months ago

Print the following pattern in c program

5 4 3 2 1
4 3 2 1
3 2 1
21
1
Sample testcases
Input 1
Output 1
5
Enter the number of rows:
5 4 2 1
4 3 2 1
3 2 1
2 1
1​

Answers

Answered by anindyaadhikari13
1

Answer:

This is the required C program for the question.

#include <stdio.h>

int main () {

int i,j,n;

printf("Enter number of rows - ");

scanf("%d",&n);

printf("Here is your pattern.\n");

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

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

printf("%d ",j);

printf("\n");

}

return 0;

}

Algorithm:

  1. START.
  2. Accept the number of rows(n).
  3. Iterate outer loop in range - i = n to 1.
  4. Iterate inner loop in the range j = ito 1.
  5. Print the value of j.
  6. Print a new line after displaying the row.
  7. STOP.

See the attachment for output .

Attachments:
Similar questions