Skip to main content

C Program to print Pascal's Triangle

C Program to print Pascal's Triangle


// C Program to print n Lines of Pascal's Triangle

#include <stdio.h>

int main()

{

    int rows, coeficient = 1, space, i, j;



    printf("Enter number of rows: ");

    scanf("%d",&rows);



    for(i=0; i<rows; i++)

    {

        for(space=1; space <= rows-i; space++)

            printf("  ");



        for(j=0; j <= i; j++)

        {

            if (j==0 || i==0)

                coeficient = 1;

            else

                coeficient = coeficient*(i-j+1)/j;



            printf("%4d", coeficient);

        }

        printf("\n");

    }



    return 0;

}

Output :
Enter number of rows: 
If User Inputs 6 Then outout Is -
1
11
121
1331
14641
1 5 10 10 5 1