// Online C compiler to run C program online
#include <stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 5
int a[MAX] ,top=-1;
void push();
void pop();
void display();
int main() {
int ch;
printf("1. Push or insert\n");
printf("2. Pop or delete\n");
printf("3. display \n");
printf("4. exit\n");
// Write C code here
while(1){
printf("\n enter choice");
scanf("%d",&ch);
switch(ch){
case 1:
{
push();
break;
}
case 2 :
{
pop();
break;
}
case 3 :
{
display();
break;
} case 4 :
{
exit(0);
}
default :{
printf("invalid input");
}
}
getch();
return 0;
}
void push(){
int data , input;
if(top==MAX-1){
printf("overflow");
}
else {
printf("\n enter element");
scanf("%d",&data);
top++;
a[top]=data;
}
}
void pop(){
if(top==-1){
printf("underflow");
}
else{
printf("Popped elemnt%d", a[top]);
top--;
}
}
void display(){
int i;
if(top>=0){
printf("elements");
for(i=top;i>=0;i--){
printf("\n%d",a[i]);
}
}
else{
printf("empty stack");
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: