55555 4444 333 22 1
/**
* C program to print number pattern
* www.atnyla.com
*/
#include <stdio.h>
int main()
{
int i, j, N;
printf("Enter N: ");
scanf("%d", &N);
for(i=N; i>=1; i--)
{
for(j=1; j<=i; j++)
{
printf("%d", i);
}
printf("\n");
}
return 0;
}
Enter N: 5
55555
4444
333
22
1
Basic C programming, Loop
Before we discuss about logic of printing these patterns. I would recommend you to check out some similar number patterns. As both of the patterns mentioned in this program are just vertically flipped image of
1 22 333 4444 55555
Now, moving on to the logic of first pattern that we need to print. Have a careful eye on to the below pattern
55555 4444 333 22 1
Logic to print the above pattern:
And you are done, lets implement this now.
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.