C Program for Printing Pascal Triangle.
#include<stdio.h>
int fact(int m)
{
long f=1,k;
for(k=m;k>0;k--)
{
f = f * k;
}
return(f);
}
int main()
{
int n,i,j;
printf("Enter number of Rows: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=(n-i-2);j++)
{
printf(" ");
}
for(j=0;j<=i;j++)
{
printf("%d ",fact(i)/(fact(j) * fact(i-j)));
}
printf("\n");
}
return 0;
}
Input && Output
0 Comments