11111 11111 11111 11111 11111
/**
* C program to print square number pattern
* 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);
/* Iterate through rows */
for(i=1; i<=rows; i++)
{
/* Iterate through columns */
for(j=1; j<=cols; j++)
{
printf("1");
}
printf("\n");
}
return 0;
}
Enter number of rows: 5
Enter number of columns: 5
11111
11111
11111
11111
11111
Logic to print this square number pattern of 1 is simple and similar to square start pattern.
***** ***** ***** ***** *****
We only need to replace the stars(*) with 1 or 0 whatever you want to print. Basic logic to print square number pattern of n rows and m columns.
Below is the step by step descriptive logic to print square number pattern.
Note: To print rectangle number pattern, make the rows and columns different.
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.