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