Pascal Triangle in C Using Factorial
In this tutorial, we are going to see how to display pascal triangle in C using factorial. Pascal’s triangle can be constructed by first placing a 1 along the left and right edges. Then the triangle can be filled from the top by adding the two numbers just above to the left and right of each position in the triangle.

There are five ways to print pascal triangle in C, by using for loop, array, factorial, recursion, or by creating a function.
Pascal Triangle in C Using Factorial
#include <stdio.h> long fact(int n) { int i; long f = 1; for (i = 1; i <= n; i++) f = f * i; return f; } int main() { int i, j, n, space; printf("Enter the number of lines: "); scanf("%d", & n); for (i = 0; i < n; i++) { for (space = 0; space <= (n - i - 2); space++) printf(" "); for (j = 0; j <= i; j++) printf("%ld ", fact(i) / (fact(j) * fact(i - j))); printf("\n"); } return 0; }
Output:
Enter the number of lines: 7 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