Program to print the given number pattern
5
45
345
2345
12345
C Programming Language / Loop control in C Language
5340Program:
/** * 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
Output:
5 45 345 2345 12345
Explanation:
Logic to print the given number pattern
5 45 345 2345 12345
If you look to the above pattern you will find that it is same as the pattern we just printed above except of trailing spaces. Hence, the whole logic of printing the pattern will be same as first pattern, we only need to add the logic to print spaces. If you hover mouse on to the pattern you can see or count total spaces per row. In the given pattern each row contains i - 1 spaces (where i is the current row number). Note that row are in descending order i.e. row1 is 5, row2 is 4 and so on.
Step-by-step descriptive logic:
- To print spaces, run an inner loop from 1 to i. 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.