#include <stdio.h>
int main() {
char operator;
double num1, num2;
double result;
// Asking user to enter operator
printf("Enter an operator (+, -, *, /): "); scanf("\n%c", &operator
);
// Asking user to enter two operands
printf("Enter two numbers: "); scanf("%lf %lf", &num1
, &num2
);
switch (operator) {
case '+':
result = num1 + num2;
printf("%.2lf + %.2lf = %.2lf\n", num1
, num2
, result
); break;
case '-':
result = num1 - num2;
printf("%.2lf - %.2lf = %.2lf\n", num1
, num2
, result
); break;
case '*':
result = num1 * num2;
printf("%.2lf * %.2lf = %.2lf\n", num1
, num2
, result
); break;
case '/':
if (num2 != 0) {
result = num1 / num2;
printf("%.2lf / %.2lf = %.2lf\n", num1
, num2
, result
); } else {
printf("Error! Division by zero is not allowed.\n"); }
break;
default:
printf("Error! Operator is not correct.\n"); break;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpIHsKICAgIGNoYXIgb3BlcmF0b3I7CiAgICBkb3VibGUgbnVtMSwgbnVtMjsKICAgIGRvdWJsZSByZXN1bHQ7CgogICAgLy8gQXNraW5nIHVzZXIgdG8gZW50ZXIgb3BlcmF0b3IKICAgIHByaW50ZigiRW50ZXIgYW4gb3BlcmF0b3IgKCssIC0sICosIC8pOiAiKTsKICAgIHNjYW5mKCJcbiVjIiwgJm9wZXJhdG9yKTsKCiAgICAvLyBBc2tpbmcgdXNlciB0byBlbnRlciB0d28gb3BlcmFuZHMKICAgIHByaW50ZigiRW50ZXIgdHdvIG51bWJlcnM6ICIpOwogICAgc2NhbmYoIiVsZiAlbGYiLCAmbnVtMSwgJm51bTIpOwoKICAgIHN3aXRjaCAob3BlcmF0b3IpIHsKICAgICAgICBjYXNlICcrJzoKICAgICAgICAgICAgcmVzdWx0ID0gbnVtMSArIG51bTI7CiAgICAgICAgICAgIHByaW50ZigiJS4ybGYgKyAlLjJsZiA9ICUuMmxmXG4iLCBudW0xLCBudW0yLCByZXN1bHQpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlICctJzoKICAgICAgICAgICAgcmVzdWx0ID0gbnVtMSAtIG51bTI7CiAgICAgICAgICAgIHByaW50ZigiJS4ybGYgLSAlLjJsZiA9ICUuMmxmXG4iLCBudW0xLCBudW0yLCByZXN1bHQpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlICcqJzoKICAgICAgICAgICAgcmVzdWx0ID0gbnVtMSAqIG51bTI7CiAgICAgICAgICAgIHByaW50ZigiJS4ybGYgKiAlLjJsZiA9ICUuMmxmXG4iLCBudW0xLCBudW0yLCByZXN1bHQpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlICcvJzoKICAgICAgICAgICAgaWYgKG51bTIgIT0gMCkgewogICAgICAgICAgICAgICAgcmVzdWx0ID0gbnVtMSAvIG51bTI7CiAgICAgICAgICAgICAgICBwcmludGYoIiUuMmxmIC8gJS4ybGYgPSAlLjJsZlxuIiwgbnVtMSwgbnVtMiwgcmVzdWx0KTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHByaW50ZigiRXJyb3IhIERpdmlzaW9uIGJ5IHplcm8gaXMgbm90IGFsbG93ZWQuXG4iKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICBwcmludGYoIkVycm9yISBPcGVyYXRvciBpcyBub3QgY29ycmVjdC5cbiIpOwogICAgICAgICAgICBicmVhazsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=