Pascal Triangle

What is the C program for Pascal Triangle
1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 5 1

Questions by sadique_ghitm   answers by sadique_ghitm

Showing Answers 1 - 1 of 1 Answers

Bhuvani.v

  • Nov 11th, 2007
 

#include<stdio.h>
main()
{
int binom,p,q,r,x;
binom=1;
q=0;
printf("Input the number of rows:");
scanf("%d",&p);
printf("Pascal's triangle:n");
while(q<p)
{
for(r = 0;r>0;--r)
printf(" ");
for(x=0; x<=q;++x)
{
 if((x==0)||(q==0))
 {
 binom=1;
 
 }
 else
 {
 binom=(binom*(q-x+1))/x;
 
 }
printf("%2d ",binom);
}
printf("n");
++q;

}}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions