Monday, 13 December 2010

Program 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

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int  num,i,y,x=35; clrscr();

printf("\nEnter the number to generate the pyramid:\n"); scanf("%d",&num);
for(y=0;y<=num;y++)
{
/*(x-coordinate,y-coordinate)*/
gotoxy(x,y+1);
/*for displaying digits towards the left and right of zero*/ for(i=0-y;i<=y;i++)
  printf("%3d",abs(i));
  x=x-3;

}
getch();
}



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