#include <stdio.h>
#include <stdlib.h>
//stack using array
int main()
{
int stack[10],size,top=0,choice,element;
printf("enter the stack size");
scanf("%d",&size);
while(1){
printf("\n choose option \n 1.push \n 2. pop \n 3.display \n 4. exit");
scanf("%d",&choice);
system("cls");
switch(choice){
case 1:
if(top<size){
printf("enter element to be inserted");
scanf("%d",&element);
stack[top]=element;
top++;
}
else{
printf("stack full!");
}
break;
case 2:
if(top>0){
top--;
printf("the deleted element is:%d",stack[top]);
}
else{
printf("stack empty");
}
break;
case 3:
for(element=0;element<top;element++){
printf(" %d",stack[element]);
}
break;
case 4:
exit(0);
}
}
return 0;
}
#include <stdlib.h>
//stack using array
int main()
{
int stack[10],size,top=0,choice,element;
printf("enter the stack size");
scanf("%d",&size);
while(1){
printf("\n choose option \n 1.push \n 2. pop \n 3.display \n 4. exit");
scanf("%d",&choice);
system("cls");
switch(choice){
case 1:
if(top<size){
printf("enter element to be inserted");
scanf("%d",&element);
stack[top]=element;
top++;
}
else{
printf("stack full!");
}
break;
case 2:
if(top>0){
top--;
printf("the deleted element is:%d",stack[top]);
}
else{
printf("stack empty");
}
break;
case 3:
for(element=0;element<top;element++){
printf(" %d",stack[element]);
}
break;
case 4:
exit(0);
}
}
return 0;
}