Pascal Triangle in C Using Function
In this tutorial, we are going to see how to display pascal triangle in C using function. 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.
[st_adsense]
Pascal Triangle in C Using Function
#include <stdio.h> int factorial(int x){ int i, f=1; if(x==0) return 1; for (i=x; i>0; i--) f*=i; return f; } int coeff(int n, int y){ return (factorial(n))/(factorial(y)*factorial(n-y)); } int main(){ int n,i,j,space = 0; printf("Enter the number of lines: "); scanf("%d",&n); for (i=0;i<=n;i++){ for(space=n; space>i; space--) printf(" "); for(j=0;j<=i;j++) printf("%4d",coeff(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[st_adsense]