fork download
  1. #include<stdio.h>
  2.  
  3. #define SIZE 10
  4. double stack[SIZE];
  5. int sp;
  6.  
  7. void push(double value);
  8. double pop(void);
  9. int isFull(void);
  10. int isEmpty(void);
  11. void answer(void);
  12. void reset(void);
  13.  
  14. int main(void)
  15. {
  16. reset();
  17. int a,i;
  18. double data;
  19. while(1){
  20. scanf("%d",&a);
  21. if (!a) break;
  22. switch(a){
  23. case 1:for(i=0;i<sp;i++)
  24. data = data +stack[i];
  25. push(data);break;
  26. case 5:scanf("%f",&data);printf("%f ",data);push(data);break;
  27. case 9: a=0;break;
  28. }
  29.  
  30.  
  31. }
  32.  
  33. answer();
  34.  
  35. return 0;
  36. }
  37. void push(double value){
  38. if(isFull())printf("満杯");
  39. else stack[sp++] = value;}
  40.  
  41. double pop(void){
  42. if(isEmpty()){printf("空");return 0;}
  43. else return stack[--sp];
  44. }
  45.  
  46. int isFull(void){
  47. if (sp >=SIZE) return 1;
  48. else return 0;
  49. }
  50.  
  51. int isEmpty(void){
  52. if(sp <= 0)return 1;
  53. else return 0;
  54. }
  55.  
  56. void answer(void){
  57. printf("%f",stack[1]);
  58. }
  59.  
  60. void reset(void){
  61. sp = 0;
  62. }
Success #stdin #stdout 0s 5284KB
stdin
5
1
5
2
9
stdout
0.000000 0.000000 0.000000