C 语言-简单计算器
简单计算器
http://www.nowcoder.com/questionTerminal/b8f770674ba7468bb0a0efcc2aa3a239
#include<stdio.h> int main() { double a,b;//最初用float,通过率90% char o; while(scanf("%lf%c%lf",&a,&o,&b)!=EOF) { switch(o) { case '+':printf("%.4f+%.4f=%.4f\n",a,b,a+b);break; case '-':printf("%.4f-%.4f=%.4f\n",a,b,a-b);break; case '*':printf("%.4f*%.4f=%.4f\n",a,b,a*b);break; case '/': if(b==0) { printf("Wrong!Division by zero!\n"); } else { printf("%.4f/%.4f=%.4f\n",a,b,a/b); } break; default:printf("Invalid operation!\n");break; } } return 0; }
参考资料:https://www.runoob.com/cprogramming/c-examples-calculator-switch-case.html