Example:
Input rows: 5
Input cols: 5
Output:
Required knowledge
Basic C programming, LoopLogic to print circle box number pattern
Before you move on to this number pattern I recommend you to learn one of the similar number pattern. As this program is almost similar to the above mentioned pattern.Talking about this pattern, it consists of following noticeable things:
- Zeros are printed in center and at the corners.
- Ones are printed at the edges.
Program to print circle box number pattern
/** * C program to print circle box number pattern */ #include <stdio.h> int main() { int i, j, N; printf("Enter rows: "); scanf("%d", &N); for(i=1; i<=N; i++) { for(j=1; j<=N; j++) { //Print corner elements if((i==1 || i==N) && (j==1 || j==N)) { printf("0"); } else if(i==1 || i==N || j==1 || j==N) { //Print edges printf("1"); } else { //Print center printf("0"); } } printf("\n"); } return 0; }
Output
Enter rows: 5
01110
10001
10001
10001
01110
01110
10001
10001
10001
01110
Snapshot
Now once you are done with the above pattern you can easily play with the inner printf() statements to get following cool patterns of 0's and 1's.
10001 01110 01110 01110 10001
111 1 1 1 1 1 1 111
000 0 0 0 0 0 0 000
1 1 111 111 111 1 1
0 0 000 000 000 0 0
Happy coding ;)