#include <stdio.h>
#include <stdlib.h>
long factorial(int);
long comb(int,int);
int main()
{
int i,j,k;
printf ("Enter number of rows for pascal triangles\n");
scanf ("%d", &k) ;
for(i=0;i<k;i++)
{
for(j=0;j<=i;j++)
printf("%5ld",comb(i,j));
printf("\n") ;
}
}
long comb(int n,int r)
{
long c;
c=factorial(n)/(factorial(r)*factorial(n-r));
return c;
}
long factorial (int k)
{
long fact=1;
while(k>0)
{
fact*=k;
k--;
}
return fact;
}
output:
Enter number of rows for pascal triangles
5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1