Sunday, 12 December 2010

Program for To generate Pascal’s triangle

#include<stdio.h>
#include<conio.h>

void main()

{
 int  i,p,r,x,binom=1;
 clrscr();

printf("enter the how many lines to print"); scanf("%d",&p);
i=0;
while(i<p) // check the condition
{
for(r=40-i;r>0;r--) // perform the looping operation until 0  
printf(" ");
for(x=0;x<=i;x++)
{
if((x==0)||(i==0)) // check the condition binom=1;
else
binom=binom*(i-x+1)/x; printf("%d",binom);
printf(" ");
}
printf("\n");
i++;
}
getch();
}

Output:


1.enter the how many lines to print5
     1
 1 1
1  2     1
1 3  3 1
1  4  6  4 1

2.enter the how many lines to  print3

 1
1 1
 1 2 1



Conclusion: the program is error free


VIVA QUESTIONS:

1) What is meant by Pascal’s triangle ?

Ans: Pascal’s triangle which is used for a coefficient in the equation in polynominals

2)Define structure ?

Ans: A structure in c is a heterogenous user efined data type. A structure may contain different data types.It groups variables into a single entity.



Algorithm


No comments:

Post a Comment