Pattern except center all are 1,center is 0:

#include <stdio.h>
int main()
{
    int rows, cols, i, j;
    int centerRow, centerCol;
    scanf("%d", &rows);
    scanf("%d", &cols);
    centerRow = (rows + 1) / 2;
    centerCol = (cols + 1) / 2;
     if(rows>0 && cols>0)
     {
    for(i=1; i<=rows; i++)
    {
        for(j=1; j<=cols; j++)
        {
            if(centerCol == j && centerRow == i)
            {
                printf("0");
            }
            else if(cols%2 == 0 && centerCol+1 == j)
            {
                if(centerRow == i || (rows%2 == 0 && centerRow+1 == i))
                    printf("0");
                else
                    printf("1");
            }
            else if(rows%2 == 0 && centerRow+1 == i)
            {
                if(centerCol == j || (cols%2 == 0 && centerCol+1 == j))
                    printf("0");
                else
                    printf("1");
            }
            else
            {
                printf("1");
            }
        }

        printf("\n");
    }
   
     }else
    printf("You entered 0.");
   

    return 0;
}

Comments