C program to print numbers in pattern 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1

PROGRAM:

To print number in pattern given below:

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


#include <stdio.h>
int main()
{
    int n,i,j;
    printf("Enter no. of lines \n");
    scanf("%d",&n);
    for(i=n-1;i>=0;i--)
    {
        for(j=i;j>0;j--)
        {
            printf("  ");
        }
        for(j=1;j<=n-i;j++)
        {
            printf("%d ",j);
        }
        for(j=n-i-1;j>0;j--)
        {
            printf("%d ",j);
        }
        printf("\n");
    }
    return 0;
}


OUTPUT:

Enter no. of lines
5
        1
      1 2 1
    1 2 3 2 1
  1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1

Popular Posts