fork download
  1. #include<stdio.h>
  2. int push(int[],int);
  3. int pop(int[],int);
  4. void disp(int[],int);
  5. int main()
  6. {
  7. int max;
  8. printf("enter size of stack");
  9. scanf("%d",&max);
  10. int stack[max];
  11. int top=-1;
  12. int c,u=0;
  13. do
  14. {
  15. printf("enter choice\n1.for push\n2.for pop\n3.for disp");
  16. scanf("%d",&c);
  17. switch(c)
  18. {
  19. case 1:
  20. if(top==(max-1))
  21. printf("stack overflow");
  22. else
  23. top=push(stack,top);
  24. break;
  25. case 2:
  26. if(top==(-1))
  27. printf("stack underflow");
  28. else
  29. top=pop(stack,top);
  30. break;
  31. case 3:
  32. disp(stack,top);
  33. default:printf("invalid input");
  34. break;
  35. }
  36. printf("wanna continue");
  37. scanf("%d",&u);
  38. }
  39. while(u==1);
  40. return 0;
  41. }
  42. int push(int s[],int n)
  43. {
  44. scanf("%d",&s[n]);
  45. n++;
  46. return n;
  47. }
  48. int pop(int s[],int n)
  49. {
  50. printf("popped %d",s[n]);
  51. n--;
  52. return(n);
  53. }
  54. void disp(int s[],int n)
  55. {
  56. int i;
  57. for(i=n;i>=0;i++)
  58. {
  59. printf("%d",s[i]);
  60. }
  61. }
  62.  
  63.  
  64.  
  65.  
Success #stdin #stdout 0s 5512KB
stdin
Standard input is empty
stdout
enter size of stackenter choice
1.for push
2.for pop
3.for dispinvalid inputwanna continue