题解 | #简单计算器#
简单计算器
https://www.nowcoder.com/practice/b8f770674ba7468bb0a0efcc2aa3a239
#include <stdio.h> int main() { double n1 = 0.0; double n2 = 0.0; char op = 0; while (~scanf("%lf%c%lf", &n1, &op, &n2)) { switch (op) { case'+': printf("%.4lf+%.4lf=%.4lf\n", n1, n2, n1 + n2); break; case'-': printf("%.4lf-%.4lf=%.4lf\n", n1, n2, n1 - n2); break; case'*': printf("%.4lf*%.4lf=%.4lf\n", n1, n2, n1 * n2); break; case'/': if (0.0 == n2) { printf("Wrong!Division by zero!\n"); } else { printf("%.4lf/%.4lf=%.4lf\n", n1, n2, n1 / n2); } break; default: printf("Invalid operation!\n"); break; } } return 0; }
c语言刷题 文章被收录于专栏
c语言刷题题目