• Source
    1. #include<stdio.h>
    2. #include<stdlib.h>
    3. #define MAXSIZE 10
    4. int s[MAXSIZE],top=-1;
    5. void push(int x)
    6. {
    7. if(top==MAXSIZE-1)
    8. printf("\n Stack Overflow.");
    9. else
    10. {
    11. top++;
    12. s[top]=x;
    13. }
    14. }
    15. void pop()
    16. {
    17. int temp;
    18. if(top==-1)
    19. printf("\n Stack Underflow.");
    20. else
    21. {
    22. temp=s[top];
    23. printf("\n %d is Popped from Stack.",temp);
    24. top--;
    25. }
    26. }
    27. void display()
    28. {
    29. int i;
    30. printf("\n The Stack Elements are...\n");
    31. if(top==-1)
    32. {
    33. printf("\n No Elements to display.");
    34. }
    35. else
    36. {
    37. for(i=top;i>=0;i--)
    38. printf(" %d ",s[i]);
    39. }
    40. }
    41. int main()
    42. {
    43. int choice,x;
    44. while(1)
    45. {
    46. printf("\n1. Push\n2. Pop\n3. Display\n4. Exit");
    47. printf("\n Please, Enter your choice : ");
    48. scanf("%d",&choice);
    49. switch(choice)
    50. {
    51. case 1 : printf("\n Enter Element : ");
    52. scanf("%d",&x);
    53. push(x);
    54. break;
    55. case 2 : pop();
    56. break;
    57. case 3 : display();
    58. break;
    59. case 4 : exit(0);
    60. default : printf("\n Wrong Choice.");
    61. }
    62.  
    63. }
    64. }