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