题解 | #简单计算器#
简单计算器
https://www.nowcoder.com/practice/5759c29a28cb4361bc3605979d5a6130
#include <stdio.h> int main() { double a, s[300], sum, temp; char op; while (scanf("%lf", &a) != EOF) { if (a == 0) { break; } sum = 0; int i = 0; s[0] = a; getchar(); while (scanf("%c", &op) != EOF && op != '\n') { getchar(); scanf("%lf", &temp); getchar(); if (op == '+') { s[++i] = temp; } else if (op == '-') { s[++i] = 0 - temp; } else if (op == '*') { s[i] *= temp; } else if (op == '/') { s[i] /= temp; } } for (int j = 0; j <= i; j++) { sum += s[j]; } printf("%.2lf\n", sum); } return 0; }