Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- pattern_centre_v1.c
- Task:
- https://web.facebook.com/groups/c.programing/permalink/1572862292872615/
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- void print_pattern( int n )
- {
- int r, c; // r is row, c is column
- for(c=0; c<n; c++)
- {
- for(r=0; r<n; r++)
- {
- if(n%2) // if n is odd
- {
- if( r==n/2 && c==n/2 )
- printf("1");
- else
- printf("2");
- }
- else // if n is even
- {
- if( (r==n/2-1 || r==n/2) && (c==n/2-1 || c==n/2) )
- printf("1");
- else
- printf("2");
- }
- } // for(r=0; r<n; r++)
- printf("\n");
- } // for(c=0; c<n; c++)
- printf("\n");
- }
- int main(void)
- {
- print_pattern(3);
- print_pattern(4);
- print_pattern(5);
- print_pattern(6);
- print_pattern(7);
- print_pattern(8);
- return 0;
- } // main()
Add Comment
Please, Sign In to add comment