-->

C program to print square numeric pattern 12345

**
 * C program to print square numeric pattern
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5

1 2 3 4 5

1 2 3 4 5

 */
#include <stdio.h>
#include<conio.h>
void main()
{
    int i, j, N;

    /* Input number of rows from user */
    printf("Enter number of rows: ");
    scanf("%d", &N);

    /* Iterate over each row */
    for(i=1; i<=N; i++)
    {
                /* Print given number in next line */
                printf("1 2 3 4 5\n");
   
    }

    getch();
}

C program to print box number pattern with alternative 2 and 0

/**
 *
 2 2 2 2 2
 0 0 0 0 0
 2 2 2 2 2
 0 0 0 0 0
 2 2 2 2 2
 */
#include <stdio.h>
#include<conio.h>
void main()
{
    int rows, cols, i, j;

    /* Input rows and columns from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    printf("Enter number of columns: ");
    scanf("%d", &cols);

    for(i=1; i<=rows; i++)
    {
        for(j=1; j<=cols; j++)
        {
            if((i%2)!=0)
            printf("2");
            else
            printf("0");
        }

        printf("\n");
    }

    getch();
}

C program to print box number pattern with alternative 1 and 0

/**
 * C program to print box number pattern
 1 1 1 1 1
 0 0 0 0 0
 1 1 1 1 1
 0 0 0 0 0
 1 1 1 1 1
 */
#include <stdio.h>
#include<conio.h>
void main()
{
    int rows, cols, i, j;

    /* Input rows and columns from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    printf("Enter number of columns: ");
    scanf("%d", &cols);

    for(i=1; i<=rows; i++)
    {
        for(j=1; j<=cols; j++)
        {
            printf("%d", (i%2));
        }

        printf("\n");
    }

    getch();
}

                                                                                                                  source: codeforwin.org

C program to print square numeric pattern

/**
 * C program to print square numeric pattern
   0 2 0 2 0
   0 2 0 2 0
   0 2 0 2 0
   0 2 0 2 0
   0 2 0 2 0

 */
#include <stdio.h>
#include<conio.h>
void main()
{
    int i, j, N;

    /* Input number of rows from user */
    printf("Enter number of rows: ");
    scanf("%d", &N);

    /* Iterate over each row */
    for(i=1; i<=N; i++)
    {
                /* Print given number in next line */
                printf("0 2 0 2 0\n");
   
    }

    getch();
}

C program to print square star pattern with zeros

/**
 * C program to print hollow square star pattern
   x x x x x
   x 0 0 0 x
   x 0 0 0 x
   x 0 0 0 x
   x x x x x


 */

#include <stdio.h>
#include<conio.h>
void main()
{
    int i, j, N;

    /* Input number of rows from user */
    printf("Enter number of rows: ");
    scanf("%d", &N);

    /* Iterate over each row */
    for(i=1; i<=N; i++)
    {
        /* Iterate over each column */
        for(j=1; j<=N; j++)
        {
            if(i==1 || i==N || j==1 || j==N)
            {
                /* Print star for 1st, Nth row and column */
                printf("x");
            }
            else
            {
                printf("0");
            }
        }

        /* Move to the next line/row */
        printf("\n");
    }

    getch();
}

                                                                                                    source:codeforwin.org

C program to print hollow numeric star pattern

/**
 * C program to print hollow numeric star pattern
 1 1 1 1 1
 1          1
 1          1
 1          1
 1 1 1 1 1

 */

#include <stdio.h>
#include<conio.h>
void main()
{
    int i, j, N;

    /* Input number of rows from user */
    printf("Enter number of rows: ");
    scanf("%d", &N);

    /* Iterate over each row */
    for(i=1; i<=N; i++)
    {
        /* Iterate over each column */
        for(j=1; j<=N; j++)
        {
            if(i==1 || i==N || j==1 || j==N)
            {
                /* Print star for 1st, Nth row and column */
                printf("1");
            }
            else
            {
                printf(" ");
            }
        }

        /* Move to the next line/row */
        printf("\n");
    }

    getch();
}

C program to print box number pattern with alternative 0 and 1


/**
 * C program to print box number pattern 
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
 */

#include <stdio.h>
#include<conio.h>
void main()
{
    int rows, cols, i, j, k;

    /* Input rows and columns from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    printf("Enter number of columns: ");
    scanf("%d", &cols);

    k = 1;

    for(i=1; i<=rows; i++)
    {
        for(j=1; j<=cols; j++)
        {
            if(k == 1)
            {
                printf("1");
            }
            else
            {
                printf("0");
            }

            // If k = 1  then k *= -1 => -1
            // If k = -1 then k *= -1 =>  1
            k *= -1;
        }

        if(cols % 2 == 0)
        {
            k *= -1;
        }

        printf("\n");
    }

    getch();
}
                                                           source :codeforwin.org