Translate

Labels

Saturday 8 June 2013

PASCAL'S TRIANGLE

#include<stdio.h>
#include<conio.h>
main()
{
int b,p,q,r,x;
clrscr();
printf("Enter no.of rows:");
scanf("%d",&r);
b=1;
q=0;
printf("\n PASCAL'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++;
}
getch();
}

OUTPUT:
Enter no.of rows:4
PASCAL'S TRIANGLE:
       1
    1    1
  1   2   1
1   3   3  1

No comments: