pascal triangle program in c
#include<stdio.h>
int factorial(int a)
{
int product = 1;
while(a>0)
{
product *= a;
a -= 1;
}
return product;
}
int combinations(int n, int r)
{
int numerator=factorial(n);
int denominator=(factorial(r))*(factorial(n-r));
return numerator/denominator;
}
int main()
{
int n,i,j,k;
printf("Enter value of n\n");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=0;j<=(n-i);j++)
{
printf(" ");
}
for(k=0; k<=i;k++)
{
printf("%d ",combinations(i,k));
}
printf("\n");
}
}