01110 10001 10001 10001 01110
/**
* C program to print circle box number pattern
* www.atnyla.com
*/
#include <stdio.h>
int main()
{
int i, j, rows, cols;
/* Input rows and columns from user */
printf("Enter rows: ");
scanf("%d", &rows);
printf("Enter columns: ");
scanf("%d", &cols);
for(i=1; i<=rows; i++)
{
for(j=1; j<=cols; j++)
{
// Print corner element
if((i==1 || i==rows) && (j==1 || j==cols))
{
printf("0");
}
else if(i==1 || i==rows || j==1 || j==cols)
{
// Print edge
printf("1");
}
else
{
// Print center
printf("0");
}
}
printf("\n");
}
return 0;
}
Enter rows: 5
Enter columns: 5
01110
10001
10001
10001
01110
Basic C programming, Loop
The given pattern is almost similar to one of previous explained pattern -
11111 10001 10001 10001 11111
The only difference is zero gets printed for corner elements instead of 1.
Below is the step by step descriptive logic to print the given pattern.
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.