#include <stdio.
h>
int stack[100], choice, n, top = -1, x;
void push(void);
void pop(void);
void display(void);
int main() {
printf("\nEnter the size of stack: ");
scanf("%d", &n);
printf("\n\tStack operations using array:");
printf("\n\t-----------------------------------------");
printf("\n\t1. Push\n\t2. Pop\n\t3. Display\n\t4. Exit");
do {
printf("\nEnter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
printf("Exiting program...\n");
break;
default:
printf("Invalid choice! Try again.\n");
} while (choice != 4);
return 0;
void push() {
if (top >= n - 1) {
printf("Stack Overflow! Cannot push more elements.\n");
} else {
printf("Enter value to push: ");
scanf("%d", &x);
top++;
stack[top] = x;
printf("%d pushed to stack\n", x);
}
void pop() {
if (top <= -1) {
printf("Stack Underflow! Cannot pop\n");
} else {
printf("%d popped from stack\n", stack[top]);
top--;
void display() {
if (top >= 0) {
printf("Stack elements:\n");
for (int i = top; i >= 0; i--) {
printf("%d\n", stack[i]);
} else {
printf("Stack is empty\n");