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