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