Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main (){
- int a, b, c, x; //a = firstNum, b = secondNum, c = total, x = holds the switch value.
- printf("Mathematical Operators\n");
- printf("1 for Addition\n");
- printf("2 for Subtraction\n");
- printf("3 for Multiplication\n");
- printf("4 for Division\n");
- printf("Select operator: ");
- while (scanf("%d", &x) == 1){
- switch (x){
- case 1:
- printf("Enter First Number: ");
- scanf("%d", &a);
- printf("Enter Second Number: ");
- scanf("%d", &b);
- c = a + b;
- printf("\nThe sum of %d and %d is %d", a, b, c);
- break;
- case 2:
- printf("Enter First Number: ");
- scanf("%d", &a);
- printf("Enter Second Number: ");
- scanf("%d", &b);
- c = a - b;
- printf("\nThe difference of %d and %d is %d", a, b, c);
- break;
- case 3:
- printf("Enter First Number: ");
- scanf("%d", &a);
- printf("Enter Second Number: ");
- scanf("%d", &b);
- c = a * b;
- printf("\nThe product of %d and %d is %d", a, b, c);
- break;
- case 4:
- printf("Enter First Number: ");
- scanf("%d", &a);
- printf("Enter Second Number: ");
- scanf("%d", &b);
- c = a / b;
- printf("\nThe quotient of %d and %d is %d", a, b, c);
- break;
- default:
- printf("Invalid argument.");
- break;
- }
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement