题解 | #简单计算器#
简单计算器
https://www.nowcoder.com/practice/b8f770674ba7468bb0a0efcc2aa3a239
#include <stdio.h> int main() { double a = 0.0, b = 0.0; char c = 0; scanf("%lf%c%lf", &a, &c, &b); if (c != '+' && c != '-' && c != '*' && c != '/') printf("Invalid operation!"); else { if (b == 0.0 && c == '/') printf("Wrong!Division by zero!"); else { switch (c) { case '+': printf("%.4f+%.4f=%.4f", a, b, a + b); break; case '-': printf("%.4f-%.4f=%.4f", a, b, a - b); break; case '*': printf("%.4f*%.4f=%.4f", a, b, a * b); break; case '/': printf("%.4f/%.4f=%.4f", a, b, a / b); break; } } } return 0; }