Advertisement
dmilicev

chessboard_pattern_v1.c

Oct 25th, 2023
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. /*
  2.  
  3.     chessboard_pattern_v1.c
  4.  
  5. https://www.facebook.com/groups/3092811364081112/?multi_permalinks=7271679206194286&ref=share
  6.  
  7.  
  8.     You can find all my C programs at Dragan Milicev's pastebin:
  9.  
  10.     https://pastebin.com/u/dmilicev
  11.  
  12. */
  13.  
  14. #include <stdio.h>
  15.  
  16. void print_chessboard_pattern(int n){
  17.     for(int a=1; a<=n; a++)
  18.         if(a%2!=0)
  19.             for(int i=1; i<=n; i++){
  20.                 for(int j=1; j<=n; j++)
  21.                     if(j%2!=0)
  22.                         for(int k=1; k<=n; k++)
  23.                             printf("  ");
  24.                     else
  25.                         for(int k=1; k<=n; k++)
  26.                             printf("* ");
  27.                 printf("\n");
  28.             }
  29.         else
  30.             for(int i=1; i<=n; i++){
  31.                 for(int j=1; j<=n; j++)
  32.                     if(j%2!=0)
  33.                         for(int k=1; k<=n; k++)
  34.                             printf("* ");
  35.                     else
  36.                         for(int k=1; k<=n; k++)
  37.                             printf("  ");
  38.                 printf("\n");
  39.             }
  40. }
  41.  
  42. int main(void){
  43.     int n=6;
  44.  
  45.     for(int i=2; i<=n; i++){
  46.         printf("\n n = %d \n\n",i);
  47.         print_chessboard_pattern(i);
  48.         printf("\n\n");
  49.     }
  50.  
  51.     return 0;
  52. } // main()
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement