Monday 13 December 2010

Algorithm for To construct a pyramid of numbers

Objective :

To construct a pyramid of numbers

Description:


In this program the we have to construct output in the pyramid shape manner


Algorithm:


Step 1: Start
Step 2: initialize the num,I,y, x=35 Step 3: read the num
Step 4:perform the loop operation

For(y=0;y<=num;y++)
Step 5:Gotoxy(x,y+1)
Step 6: perform the loop operation for displaying digits towards the left and right For(i=0-y;i<=y;i++)
Step 7: print abs(i);
Step 8: x=x-2;

Step 9: Stop

Output:

1.enter the number:
4


      0

      
 1 0 1


       2 1 0 1 2


3 2 1 0 1 2 3

                              
     4 3 2 1 0 1 2 3 4

      2.enter the number :3


                   0


1 0 1


2 1 0 1
 2

           3 2 1 0 1 2 3
Conclusion: The program is error free

VIVA QUESTIONS:

1)  What is the use of dot operator in structures ?
Ans: The use of dot(.) operator to access the members of a structure independently. The dot operator connects a member with the structure variable.
2)  Define unions ?

Ans: A union is a data type in c which allows the overlay of more than one variable in the same memory area.


c programs


No comments:

Post a Comment