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