fork download
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int stack[10];
  5. int max;
  6. int num;
  7. int top = -1;
  8. int i;
  9. int item;
  10. //printf("Enter the maximum size of stack");
  11. scanf("%d",&max);
  12. //printf("Enter the no of elements in stack");
  13. scanf("%d",&num);
  14.  
  15. //printf("Enter the elements of stack");
  16. for(i=0;i<num;i++)
  17. {
  18. scanf("%d\n",&stack[i]);
  19. top++;
  20. }
  21.  
  22.  
  23. if(top == max -1)
  24. {
  25. printf("Overflow");
  26. }
  27. else
  28. {
  29. //printf("Enter the item you want to insert\n");
  30. scanf("%d",&item);
  31. top = top + 1;
  32. stack[top] = item;
  33. printf("The stack after push operation is \n");
  34. for(i=num;i>=0;i--)
  35. {
  36. printf("%d\n",stack[i]);
  37. top--;
  38. }
  39. }
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 2252KB
stdin
10
4

10
310
105
85

70



stdout
The stack after push operation is 
70
85
105
310
10