Untitled

 avatar
unknown
plain_text
4 years ago
1.8 kB
5
Indexable
/*AMAN KUMAR
20201COM0054
3 COM 3
mid term exam*/
#include<stdio.h>
int stack[100],choice,n,top,x,i;
void push(void);
void pop(void);
void display(void);
int main()
{

    top=-1;
    printf("\n Enter the number of chairs to be piled[MAX=100]:");
    scanf("%d",&n);
    printf("\n STACK OPERATIONS USING ARRAY  FOR UNIVERSITY");

    printf("\n\t 1.ADD\n\t 2.DELETE\n\t 3.DISPLAY\n\t 4.EXIT");
    do
    {
        printf("\n Enter the Choice:");
        scanf("%d",&choice);
        switch(choice)
        {
            case 1:
            {
                push();
                break;
            }
            case 2:
            {
                pop();
                break;
            }
            case 3:
            {
                display();
                break;
            }
            case 4:
            {
                printf("\n\t DONE WITH THE PILING OF CHAIRS ");
                break;
            }
            default:
            {
                printf ("\n\t Enter a Valid Choice!!!!");
            }

        }
    }
    while(choice!=4);
    return 0;
}
void push()
{
    if(top>=n-1)
    {
        printf("\n\tNO MORE CHAIRS CAN BE PILED");

    }
    else
    {
        printf(" ADD THE NUMBER OF THE CHAIR TO BE PILED:");
        scanf("%d",&x);
        top++;
        stack[top]=x;
    }
}
void pop()
{
    if(top<=-1)
    {
        printf("\n\t THERE ARE NO CHAIRS ");
    }
    else
    {
        printf("\n\t The number of the removed chair  is %d",stack[top]);
        top--;
    }
}
void display()
{
    if(top>=0)
    {
        printf("\n THE NUMBER OF CHAIRS PILED ARE AS FOLLOWS: \n");
        for(i=top; i>=0; i--)
            printf("\n%d",stack[i]);
        printf("\n Press Next Choice");
    }
    else
    {
        printf("\n THERE ARE NO CHAIRS PILED");
    }

}
Editor is loading...