Sunday, 12 December 2010

Algorithm for To generate Pascal’s triangle

Description:


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

Alogrithm:


 Step 1: Start
Step 2: Initialize m=0
Step 3: Read n
Step 4: If m<n goto step 5.if not goto step 12 Step 5: initialize i=40-m
Step 6: If i>0 is true do as follows. If not goto step 7
i.                                       print white space
ii.                                      decrement i
iii.                                    goto Step 6
Step 7: Initialize j=0
Step 8: If j=m do as follows. If not goto Step 10
i)                                             if(j==0||m==0)
ii)                                            Initialize b=1 if not b=b*(m-j+1)/j
iii)                                           Print white space, b .
iv)                                           Goto Step 9
Step 9: increment j, goto Step 8
Step 10: print new line control
Step 11: increment m, goto step 4

Step 12: Stop

Output:


1.enter the how many lines to print5
  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 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