Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- short int arithmetic (short int left, char operator, short int right) {
- if (operator == '+'){
- if ((left>0 && right>0)|| (left<0 && right<0 ) ) {
- if (((32767 - left) < right) || ( (-32767 - left) > right)) {
- printf("The result of the operation is too large to handle.\nUse -h flag for help.\n");
- exit(0);
- }
- }
- return (left+right);
- }
- if (operator == '-'){
- right = right * (-1);
- return arithmetic (left, plus, right);
- }
- if (operator == '*'){
- templ=left;
- tempr=right;
- if (left<0){
- templ=left*(-1);
- }
- if (right<0){
- tempr=right*(-1);
- }
- if ((32767/templ)<tempr){
- printf("The result of the operation is too large to handle.\nUse -h flag for help.\n");
- exit(0);
- }
- return (left*right);
- }
- if (operator == '/'){
- return (left/right);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement