11111 22222 33333 44444 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=1; j<=cols; j++)
{
// Print the current row number
printf("%d", i);
}
printf("\n");
}
return 0;
}
Enter number of rows: 5
Enter number of columns: 5
11111
22222
33333
44444
55555
Basic C programming, Loop
Below is the step by step descriptive logic to print the given number pattern.
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.