C program for Pascal’s Triangle/number pattern 20

C program for Pascal’s Triangle/number pattern 20

This program is to print Pascal’s Triangle/number pattern 20 in C.

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

If you need a dry run of the program or any other query, then kindly leave a comment in the comment box or mail me, I would be more than happy to help you.

Program

#include<stdio.h>
void main()
{
    int coef=1,space,n,i,j;

    printf("Enter no of lines\n");
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        for(space=1;space<=n-i;space++)
            printf("  ");

        for(j=0;j<=i;j++)
        {
            if (j==0 || i==0)
                coef = 1;
            else
                coef=coef*(i-j+1)/j;

            printf("%4d",coef);
        }
        printf("\n");
    }
}

Output

Share Me!