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