In this, we are going to see a program in which we will be printing a Center Crossed Square Number pattern as shown in above image in C Programming Language.


/*Number Pattern  - (center cross)
   1 0 0 0 1
   0 1 0 1 0
   0 0 1 0 0
   0 1 0 1 0
   1 0 0 0 1
*/
#include <stdio.h>
int main()
{
    int n;

    printf("Enter no. of rows/columns: ");
    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (j != 0)
            {
                //adds space in between chars
                printf(" ");
            }
            if (j == i || j == (n - i - 1))
            {
                printf("1");
            }
            else
            {
                printf("0");
            }
        }
        printf("\n");
    }
    return 0;
}


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post