#include <stdio.h>
void main() {
int stack[20], i, n, top = -1, choice;
printf("STACK OPERATION\n\n");
printf("Enter number of elements to be stacked in: ");
scanf("%d", &n);
while (1) {
printf("\nChoose your option:\n1. Push\n2. Pop\n3. Display\n4. Exit\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
if (top >= n - 1)
{
printf("Stack Overflow!!!\n");
}
else {
top++;
printf("Enter element: ");
scanf("%d", &stack[top]);
} break;
case 2:
if (top < 0) {
printf("Stack Underflow!!!\n");
} else {
printf("Popped element: %d\n", stack[top]);
top--;
}
break;
case 3:
if (top < 0) {
printf("Stack is empty.\n");
} else {
printf("Elements in the stack:\n");
for (i = 0; i <= top; i++) {
printf("%d\n", stack[i]);
}
}
break;
case 4:
printf("Exiting the program.\n");
return;
default:
printf("Invalid choice. Please choose again.\n");
}
}
}