#include <stdio.
h> Name : Mayank Sharma
#include <stdlib.h>
int *stack, n, top;
void push()
{
int x;
if (top >= n - 1)
{
printf("\n\tSTACK is over flow");
}
else
{
printf(" Enter a value to be pushed:");
scanf("%d", &x);
top++;
stack[top] = x;
}
}
void pop()
{
if (top <= -1)
{
printf("\n Stack is under flow");
}
else
{
printf("\n The popped elements is %d", stack[top]);
top--;
}
}
void display()
{
int i;
if (top >= 0)
{
printf("\n The elements in STACK \n");
for (i = top; i >= 0; i--)
printf("\n%d", stack[i]);
}
else
{
printf("\n The STACK is empty");
}
}
int main()
{
int choice;
top = -1;
printf("\n Enter the size of STACK :");
scanf("%d", &n);
stack = (int *)malloc(n * sizeof(int));
printf("\n STACK :");
printf("\n 1.PUSH\n 2.POP\n 3.DISPLAY\n 4.EXIT");
l:
printf("\n Enter the Choice:");
scanf("%d", &choice);
if (choice == 1)
{
push();
}
else if (choice == 2)
{
pop();
}
else if (choice == 3)
{
display();
}
else if (choice == 4)
{
printf("\n EXIT");
exit(0);
}
else
{
printf("\n Please Enter a Valid Choice(1/2/3/4)");
}
goto l;
return 0;
}
OUTPUT :
SIGNATURE: