fork download
  1. #include <stdio.h>
  2. #include <stdio.h>
  3. #define max 5
  4. static int stack[max];
  5. int top=-1;
  6. void push(int x)
  7. {
  8. stack[++top]=x;
  9. }
  10. int pop()
  11. {
  12. return(stack[top--]);
  13. }
  14. void()
  15. {
  16. int i;
  17. if(pop<0)
  18. printf("stack empty")
  19. else
  20. {
  21. printf("\n top-->");
  22. for(i=top;i>0;i--)
  23. {
  24. printf("%ud",stack[i]);
  25. }
  26. printf("\n");
  27. }
  28. main()
  29. {
  30. int ch=0,val;
  31. clrscr();
  32. while(ch!=u)
  33. {
  34. printf("\n stack operations");
  35. printf("1.PUSH");
  36. printf("2.POP");
  37. printf("3.VIEW");
  38. printf("4.QUIT \n");
  39. printf("enter the choice");
  40. scanf("%d",&ch);
  41. switch(ch)
  42. {
  43. case 1:
  44. if (top<max-1)
  45. {
  46. printf("\enter the stack element ");
  47. scanf("%d",&val);
  48. }
  49. else
  50. print("\n stack overflow\n\n");
  51. break;
  52. case 2:
  53. if (top<0)
  54. printf("\n stack underflow");
  55. else
  56. {
  57. val=pop();
  58. printf("\n popped element is %d \n",val);
  59. }
  60. break;
  61. case 3:
  62. view()
  63. break;
  64. case 4:
  65. exit(0);
  66. default:
  67. printf("\n invalid choice");
  68.  
  69. }
  70. }
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
Success #stdin #stdout 0.03s 25888KB
stdin
Standard input is empty
stdout
#include <stdio.h>
#include <stdio.h>
#define max 5
static int stack[max];
int top=-1;
void push(int x)
{
 stack[++top]=x;
}
int pop()
{
 return(stack[top--]);
}
void()
{
 int i;
 if(pop<0)
 printf("stack empty")
 else
 {
 printf("\n top-->");
 for(i=top;i>0;i--)
 {
 printf("%ud",stack[i]);
 }
 printf("\n");
 }
 main()
 {
 int ch=0,val;
 clrscr();
 while(ch!=u)
 {
 printf("\n stack operations");
 printf("1.PUSH");
 printf("2.POP");
 printf("3.VIEW");
 printf("4.QUIT \n");
 printf("enter the choice");
 scanf("%d",&ch);
 switch(ch)
 {
 case 1:
 if (top<max-1)
 {
 printf("\enter the stack element ");
 scanf("%d",&val);
 }
 else
print("\n stack overflow\n\n");
break;
case 2:
if (top<0)
printf("\n stack underflow");
else
{
val=pop();
printf("\n popped element is %d \n",val);
}
break;
case 3:
view()
break;
case 4:
exit(0);
default:
printf("\n invalid choice");

 }
 }
}