Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- int a,b,result;
- char operator;
- printf("Enter two integers: ");
- scanf("%d %d", &a, &b);
- printf("Enter operation: ");
- scanf(" %c", &operator);
- switch(operator)
- {
- case '+':
- result=a+b;
- printf("Output: %d\n",result);
- break;
- case '-':
- result=a-b;
- printf("Output: %d\n",result);
- break;
- case '*':
- result=a*b;
- printf("Output: %d\n",result);
- break;
- case '/':
- {
- switch(b)
- {
- case 0:
- printf("ERROR: Divide by zero\n");
- break;
- default:
- result=a/b;
- printf("Output: %d\n",result);
- }
- }
- break;
- default:
- printf("%c is not a valid operation\n", operator);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment