题解 | #简单计算器#
简单计算器
https://www.nowcoder.com/practice/b8f770674ba7468bb0a0efcc2aa3a239
大一新生
#include <stdio.h> int main() { double a,b; char ch; scanf("%lf%c%lf",&a,&ch,&b); switch (ch) { case '+':printf("%.4lf+%.4lf=%.4lf",a,b,a+b);//加法 break; case '-':printf("%.4lf-%.4lf=%.4lf",a,b,a-b);//减法 break; case '*':printf("%.4lf*%.4lf=%.4lf",a,b,a*b);//乘法 break; case '/':if(b==0.0)//除数为零 { printf("Wrong!Division by zero!"); }else { //除数不为零 printf("%.4lf/%.4lf=%.4lf",a,b,a/b); } break; default:printf("Invalid operation!");//超范围运算符 } return 0; }