Program to print the given number pattern
12345
2345
345
45
5
C Programming Language Loop control in C Language (Article) Loop control in C Language (Program)
7914Program:
/** * C program to print number pattern * www.atnyla.com */ #include int main() { int i, j, N; printf("Enter N: "); scanf("%d", &N); for(i=1; i<=N; i++) { // Logic to print spaces for(j=1; j
Output:
12345 2345 345 45 5
Explanation:
The logic to print the given number pattern
12345 2345 345 45 5
The above pattern is similar to the pattern we just printed except the trailing spaces. The logic of this pattern would be similar as previous pattern we did, we only need to add logic to print trailing spaces before printing numbers. There are i - 1 spaces per row (where i is the current row number). To see or count total spaces per row you can hover mouse pointer to the pattern above.
Step-by-step descriptive logic:
- To print spaces, run an inner loop from 1 to i - 1 (where i is the current row number). 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.