C program to print pascal triangle


Posted On: Dec 23, 2020

C program to print pascal triangle



First of all in this article, I will give you the general introduction of Pascal Triangle. Then, I will write c program to print pascal triangle. After all, I will show its output as a pascal triangle in front of you.

Table of contents:

  1. What is Pascal’s Triangle?
  2. Demonstration of Pascal’s Triangle
  3. C program to print pascal triangle
  4. Conclusion

What is Pascal’s Triangle?

Pascal’s triangle, in algebra, a triangular arrangement of numbers that gives the coefficients in the expansion of any binomial expression, such as (x + y)n. It is named for the 17th-century French mathematician Blaise Pascal. 

To find nth term of a pascal triangle we use following formula.


Demo of Pascal Triangle

Demonstration of Pascal Triangle

Demo of Pascal Triangle

C program to print pascal triangle

#include <stdio.h>

/* Function definition */
long long fact(int n);

int main()
    int n, k, row, i;
    long long term;

    /* Input number of rows */
    printf("Enter number of rows : ");
    scanf("%d", &row);

    for(n=0; n<row; n++)
        /* Prints 3 spaces */
        for(i=n; i<=row; i++)
            printf("%3c", ' ');

        /* Generate term for current row */
        for(k=0; k<=n; k++)
            term = fact(n) / (fact(k) * fact(n-k));

            printf("%6lld", term);


    return 0;

/**Function to calculate factorial */
long long fact(int n)
    long long factorial = 1ll;
        factorial *= n;

    return factorial;

Demo of Pascal Triangle


Pascal Triangle is named as the Mathematician Blaise Pascal. This Program shows a Pascal Triangle in front of you as a output.

    Related Questions

    Please Login or Register to leave a response.

    Related Articles

    C Program Examples

    C Program to convert Decimal to Binary Number

    A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

    C Program Examples

    C program to reverse a string

    This program reversed the entered string that means opposite of the previous string sequence...

    C Program Examples

    C program to reverse an Integer number

    Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..