12345 23455 34555 45555 55555
/**
* C program to print number pattern
* www.atnyla.com
*/
#include <stdio.h>
int main()
{
int rows, cols, i, j;
/* Input rows and columns from user */
printf("Enter number of rows: ");
scanf("%d", &rows);
printf("Enter number of columns: ");
scanf("%d", &cols);
for(i=1; i<=rows; i++)
{
for(j=i; j<=cols; j++)
{
printf("%d", j);
}
for(j=i; j>1; j--)
{
printf("%d", cols);
}
printf("\n");
}
return 0;
}
Enter number of rows: 5
Enter number of columns: 5
12345
23455
34555
45555
55555
Basic C programming, Loop
Before we get into detail of printing these two patterns I assume that you all must be aware of basic number pattern printing, if not I recommend you to go through some previous number pattern to get yourself acquainted.
12345 23455 34555 45555 55555
Now, considering this pattern have an eye to this pattern carefully you will notice two separate patterns here. The two separate patterns are:
12345 2345- 345-- 45--- 5----
----- ----5 ---55 --555 -5555
Now logic to print the both patterns separately is relatively easier then whole pattern at once.
And you are done. Lets, now implement this on code.
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.