#include <stdio.h>
int main() {
char operator;
double num1, num2;
// รับค่าตัวเลขและตัวดำเนินการจากผู้ใช้
printf("Enter first number: ");
printf("Enter an operator (+, -, *, /): ");
printf("Enter second number: ");
// คำนวณตามตัวดำเนินการที่ผู้ใช้ใส่
switch (operator) {
case '+':
printf("Result: %.2f\n", num1
+ num2
); break;
case '-':
printf("Result: %.2f\n", num1
- num2
); break;
case '*':
printf("Result: %.2f\n", num1
* num2
); break;
case '/':
if (num2 != 0) {
printf("Result: %.2f\n", num1
/ num2
); } else {
printf("Error: Division by zero is not allowed.\n"); }
break;
default:
printf("Error: Invalid operator.\n"); break;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpIHsKICAgIGNoYXIgb3BlcmF0b3I7CiAgICBkb3VibGUgbnVtMSwgbnVtMjsKCiAgICAvLyDguKPguLHguJrguITguYjguLLguJXguLHguKfguYDguKXguILguYHguKXguLDguJXguLHguKfguJTguLPguYDguJnguLTguJnguIHguLLguKPguIjguLLguIHguJzguLnguYnguYPguIrguYkKICAgIHByaW50ZigiRW50ZXIgZmlyc3QgbnVtYmVyOiAiKTsKICAgIHNjYW5mKCIlbGYiLCAmbnVtMSk7CgogICAgcHJpbnRmKCJFbnRlciBhbiBvcGVyYXRvciAoKywgLSwgKiwgLyk6ICIpOwogICAgc2NhbmYoIiAlYyIsICZvcGVyYXRvcik7CgogICAgcHJpbnRmKCJFbnRlciBzZWNvbmQgbnVtYmVyOiAiKTsKICAgIHNjYW5mKCIlbGYiLCAmbnVtMik7CgogICAgLy8g4LiE4Liz4LiZ4Lin4LiT4LiV4Liy4Lih4LiV4Lix4Lin4LiU4Liz4LmA4LiZ4Li04LiZ4LiB4Liy4Lij4LiX4Li14LmI4Lic4Li54LmJ4LmD4LiK4LmJ4LmD4Liq4LmICiAgICBzd2l0Y2ggKG9wZXJhdG9yKSB7CiAgICAgICAgY2FzZSAnKyc6CiAgICAgICAgICAgIHByaW50ZigiUmVzdWx0OiAlLjJmXG4iLCBudW0xICsgbnVtMik7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgJy0nOgogICAgICAgICAgICBwcmludGYoIlJlc3VsdDogJS4yZlxuIiwgbnVtMSAtIG51bTIpOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlICcqJzoKICAgICAgICAgICAgcHJpbnRmKCJSZXN1bHQ6ICUuMmZcbiIsIG51bTEgKiBudW0yKTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgY2FzZSAnLyc6CiAgICAgICAgICAgIGlmIChudW0yICE9IDApIHsKICAgICAgICAgICAgICAgIHByaW50ZigiUmVzdWx0OiAlLjJmXG4iLCBudW0xIC8gbnVtMik7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwcmludGYoIkVycm9yOiBEaXZpc2lvbiBieSB6ZXJvIGlzIG5vdCBhbGxvd2VkLlxuIik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgcHJpbnRmKCJFcnJvcjogSW52YWxpZCBvcGVyYXRvci5cbiIpOwogICAgICAgICAgICBicmVhazsKICAgIH0KCiAgICByZXR1cm4gMDsKfQ==