C Program to Generate Cross Pattern Using Number

Generating CROSS 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(i+j==2*n)
            {
                a<=n?printf("%d",b++):printf("%d",--d);
            }
            else
            {
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}

Output of above program

Enter n: 6

1         1
 2       2
  3     3
   4   4
    5 5
     6
    5 5
   4   4
  3     3
 2       2
1         1