Program to print the given number pattern
5
54
543
5432
54321
C Programming Language / Loop control in C Language
7625Program:
/** * C program to print number pattern */ #include int main() { int i, j, N; printf("Enter N: "); scanf("%d", &N); for(i=N; i>=1; i--) { // Logic to print spaces for(j=1; j=i; j--) { printf("%d", j); } printf("\n"); } return 0; }
Output:
5 54 543 5432 54321
Explanation:
Logic to print the given number pattern
5 54 543 5432 54321
If you are done with first pattern, then logic to this wouldn't be much difficult to get. This pattern is almost similar to the previous pattern we just printed, except trailing spaces before the number. Hence, logic to print the pattern will be same as the first pattern, we only need to add the logic of printing spaces. You can hover your mouse cursor to the pattern to see or count the number of space. The pattern consists of i - 1 spaces per row (where i is the current row number). Note that in the given pattern we have assumed that row numbers are ordered descending from N-1.
Step-by-step descriptive logic to print spaces:
- To print spaces, run an inner loop from 1 to i - 1. Inside this loop print single blank space.
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.