Wednesday 28 December 2011

C program to print the Pascal's Triangle



#include<stdio.h>
main()
{
int b,p,q,r,x;
printf("Enter the number of rows\n");
scanf("%d",&r);
b=1;
q=0;
printf("\nPascal's Triangle\n");
while(q<r)
{
for(p=30-3*q;p>0;p--)
printf(" ");
for(x=0;x<=q;x++)
{
if(x==0||q==0)
b=1;
else
b=(b*(q-x+1)/x);
printf("%6d",b);
}
printf("\n");
q++;
}
}



You Like It!? Then kindly share with your Friends.
Comments
0 Comments

No comments:

Post a Comment