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