C Program to Generate Plus Pattern Using Number

Generating PLUS like pattern of number using C programming language.


#include<stdio.h>

int main()
{
    int i, j, n, a,b,c,d;

    printf("Enter n: ");
    scanf("%d", &n);

    /* Some Setup */
    a=1;
    b=1;
    c=n;
    d=n;

    /* Pattern */
    for(i=1;i<=2*n-1;i++)
    {
        for(j=1;j<=2*n-1;j++)
        {
            if(i==n)
            {
                a<=n?printf("%d",a++):printf("%d",--c);
            }
            else if(j==n)
            {
                a<=n?printf("%d",b++):printf("%d",--d);
            }
            else
            {
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}

Output of above program

Enter n: 5

    1
    2
    3
    4
123454321
    4
    3
    2
    1