Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. short int arithmetic (short int left, char operator, short int right) {
  2.  
  3. if (operator == '+'){
  4.  
  5. if ((left>0 && right>0)|| (left<0 && right<0 ) ) {
  6.  
  7. if (((32767 - left) < right) || ( (-32767 - left) > right)) {
  8.  
  9. printf("The result of the operation is too large to handle.\nUse -h flag for help.\n");
  10. exit(0);
  11. }
  12. }
  13. return (left+right);
  14. }
  15.  
  16.  
  17. if (operator == '-'){
  18. right = right * (-1);
  19. return arithmetic (left, plus, right);
  20. }
  21.  
  22.  
  23. if (operator == '*'){
  24. templ=left;
  25. tempr=right;
  26.  
  27. if (left<0){
  28. templ=left*(-1);
  29. }
  30. if (right<0){
  31. tempr=right*(-1);
  32. }
  33. if ((32767/templ)<tempr){
  34. printf("The result of the operation is too large to handle.\nUse -h flag for help.\n");
  35. exit(0);
  36. }
  37. return (left*right);
  38. }
  39. if (operator == '/'){
  40. return (left/right);
  41.  
  42. }
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement