Advertisement
Divyansh_Chourey

pattern(01)

Mar 16th, 2024 (edited)
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | Source Code | 0 0
  1. #include<stdio.h>
  2.  
  3. int main(){
  4.     int rows, columns;
  5.     printf("Enter the rows and columns: ");
  6.     scanf("%d %d", &rows, &columns);
  7.    
  8.     if((rows%2 == 0) || (columns%2 == 0)){
  9.     printf("invalid");}
  10.     else{
  11.     for(int j=1; j<=(rows/2); j++){
  12.         for(int i=1; i<=(columns/2); i++){
  13.             printf("1");
  14.         }
  15.         printf("0");
  16.         for(int i=1; i<=(columns/2); i++){
  17.             printf("1");
  18.         }
  19.         printf("\n");
  20.     }
  21.     for(int i=1; i<=(columns); i++){
  22.             printf("0");
  23.         }
  24.     printf("\n");
  25.     for(int j=1; j<=(rows/2); j++){
  26.         for(int i=1; i<=(columns/2); i++){
  27.             printf("1");
  28.         }
  29.         printf("0");
  30.         for(int i=1; i<=(columns/2); i++){
  31.             printf("1");
  32.         }
  33.         printf("\n");
  34.     }
  35.     }
  36.    
  37.     return 0;
  38. }
  39. /*OUTPUT:
  40. Enter the rows and columns: 5 5
  41. 11011
  42. 11011
  43. 00000
  44. 11011
  45. 11011
  46. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement