Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. #define size 10
  6.  
  7. double tab[size];
  8. int elem=0;
  9. void push(double liczba)
  10. {
  11.  
  12. if (elem>=10)
  13. printf("przekroczono rozmiar stosu");
  14. else
  15. {
  16. printf("dodano element %f na indeksie %d\n",liczba,elem);
  17. tab[elem]=liczba;
  18. elem++;
  19. }
  20. }
  21.  
  22. double pop()
  23. {
  24. if (elem>0)
  25. {
  26. double element=tab[elem];
  27. elem--;
  28. return element;
  29. }
  30. else
  31. {
  32. printf("stos pusty");
  33. return;
  34. }
  35.  
  36. }
  37. int main()
  38. {
  39. char ch;
  40. while(1)
  41. {
  42. ch=getchar();
  43. if (ch=='q')
  44. break;
  45. if(isdigit(ch))
  46. {
  47. int liczba=ch-'0';
  48. push(liczba);
  49. }
  50. if (!strcmp(ch,"+"))
  51. {
  52. double x=pop();
  53. double y=pop();
  54. double w=x+y;
  55. push(w);
  56. }
  57. else if (!strcmp(ch,"="))
  58. {
  59. double x=pop();
  60. printf("sciagnieto %f",x);
  61. }
  62.  
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement