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 understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.