C Program to Generate Pascal Triangle

In this program, we generate Pascal's Triangle using C language.


#include<stdio.h>

#define SIZE 20

int main()
{
    int a[SIZE], i,j,row, spi, space=36;
    printf("Enter number of rows: ");
    scanf("%d", &row);

    printf("\t\t\t\t*** PASCAL TREE ***\n");

    for(i=0;i< row;i++)
    {
        /* For Space */
        for(spi=1; spi<=space; spi++)
        {
            printf(" ");
        }

        a[i] = 1;

        for(j=0; j<=i; j++)
        {
            printf("%6d", a[j]);
        }

        for(j=i; j>=1; j--)
        {
            a[j] = a[j] + a[j-1];
        }
        space = space-3;
        printf("\n");
    }
    return 0;
}

Output of above program

Enter number of rows: 10

                  *** PASCAL TREE ***
                           1
                        1     1
                     1     2     1
                  1     3     3     1
               1     4     6     4     1
            1     5    10    10     5     1
         1     6    15    20    15     6     1
      1     7    21    35    35    21     7     1
   1     8    28    56    70    56    28     8     1
1     9    36    84   126   126    84    36     9     1