Advertisement
dmilicev

chessboard_pattern_v2.c

Oct 25th, 2023
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. /*
  2.  
  3.     chessboard_pattern_v2.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 number_of_squares, int square_size){
  17.     for(int a=1; a<=number_of_squares; a++)
  18.         if(a%2!=0)
  19.             for(int i=1; i<=square_size; i++){
  20.                 for(int j=1; j<=number_of_squares; j++)
  21.                     if(j%2!=0)
  22.                         for(int k=1; k<=square_size; k++)
  23.                             printf("  ");
  24.                     else
  25.                         for(int k=1; k<=square_size; k++)
  26.                             printf("* ");
  27.                 printf("\n");
  28.             }
  29.         else
  30.             for(int i=1; i<=square_size; i++){
  31.                 for(int j=1; j<=number_of_squares; j++)
  32.                     if(j%2!=0)
  33.                         for(int k=1; k<=square_size; k++)
  34.                             printf("* ");
  35.                     else
  36.                         for(int k=1; k<=square_size; k++)
  37.                             printf("  ");
  38.                 printf("\n");
  39.             }
  40. }
  41.  
  42. int main(void){
  43.     int number_of_squares=8, square_size=4;
  44.  
  45.     printf("\n number_of_squares = %d \t square_size = %d \n\n",
  46.             number_of_squares, square_size);
  47.     print_chessboard_pattern(number_of_squares, square_size);
  48.  
  49.  
  50.     return 0;
  51. } // main()
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement