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
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:
- START.
- Accept the number of rows(n).
- Iterate outer loop in range - i = n to 1.
- Iterate inner loop in the range j = ito 1.
- Print the value of j.
- Print a new line after displaying the row.
- STOP.
See the attachment for output ☑.
Attachments:
Similar questions