#include<stdio.h>
#include<stdlib.h>
int main(){
setbuf(stdout,NULL);
int a[50],n,k,i,ip,top;
char ch;
top=-1;
printf("Enter the size of the stack: ");
scanf("%d",&n);
do{
printf("PROGRAM TO IMPLEMENT STACK USING ARRAY\n");
printf("1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT");
printf("\nEnter the choice: ");
scanf("%d",&ip);
if(ip==1){
if(top==n-1){
printf("Stack Overflow");
}
else{
printf("Enter the element to be inserted: ");
scanf("%d",&k);
top++;
a[top]=k;
printf("The entered element is: %d",a[top]);
}
}
else if(ip==2){
if(top==-1){
printf("The Stack is Empty");
}
else{
printf("The deleted element is: %d",a[top]);
top--;
}
}
else if(ip==3){
if(top==-1){
printf("Stack Underflow");
}
else{
printf("The elements in the stack are: ");
for(i=top;i>=0;i--){
printf("\t%d",a[i]);
}
}
}
else{
break;
}
printf("\nDo you want to continue(Y/N):");
scanf("%c",&ch);
}
while((ch=='Y')||(ch=='y'));
return 0;
}
When I try running this code after taking input from the user the loop doesn't execute again. It isn't giving me any particular errors..so please can someone help me understand what's missing in the code.
The loop just runs randomly taking infinite inputs without giving any further outputs after the initial run