Advertisement
Guest User

Untitled

a guest
May 29th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5. int c, rez, br, op, i;
  6. while (1)
  7. {
  8. br = 0;
  9. rez = 0;
  10. op = 1;
  11. c = 0;
  12. while (1)
  13. {
  14. c = getchar();
  15. if (c >= '0' && c <= '9') br = br * 10 + (c - '0');
  16. else if (c == '+' || c == '-' || c == '*' || c == '=' || c == '\n')
  17. {
  18. if (op == 1)
  19. rez = rez + br;
  20. else if (op == 2)
  21. rez = rez - br;
  22. else if (op == 3)
  23. rez = rez*br;
  24. if (c == '+')
  25. op = 1;
  26. else if (c == '-')
  27. op = 2;
  28.  
  29. else if (c == '*')
  30. op = 3;
  31. else if (c == '=')
  32. op = 4;
  33.  
  34. else break;
  35.  
  36. br = 0;
  37. }
  38. }
  39. printf("Rezultat je %d\n\n", rez);
  40. }
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement