Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <stdio.h>
- #include<math.h>
- int main() {
- char operator;
- double firstNumber,secondNumber;
- printf("Enter an operator (+, -, *,/): ");
- scanf("%c", &operator);
- printf("Enter two operands: ");
- scanf("%lf %lf",&firstNumber, &secondNumber);
- switch(operator)
- {
- case '+':
- printf("%.1lf + %.1lf = %.1lf",firstNumber,secondNumber, firstNumber + secondNumber);
- break;
- case '-':
- printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber);
- break;
- case '*':
- printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber);
- break;
- case '/':
- printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber);
- break;
- default:
- printf("Error! operator is not correct");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement