#include <stdio.h>
#define SIZE 128
int stack[SIZE], top = -1;
void push(int value) {
if (top == SIZE - 1)
printf("Stack Overflow\n");
else
stack[++top] = value;
}
void pop() {
if (top == -1)
printf("Stack Underflow\n");
else
top--;
}
void display() {
if (top == -1)
printf("Stack is empty\n");
else {
printf("Stack:\n");
for (int i = top; i >= 0; i--)
printf("%d\n", stack[i]);
}
}
int main() {
push(10);
push(20);
push(30);
push(40);
display();
pop();
puts("");
display();
return 0;
}
/*
run:
Stack:
40
30
20
10
Stack:
30
20
10
*/