#include <stdio.h> int main(void){ float a, b; char ch; printf("Enter an expression:"); scanf("%f", &a); printf("%.3f", a); ch = getchar(); putchar(ch); while (ch != ‘\n‘) { scanf("%f", &b); printf("%.3f", b); switch(ch){ case ‘+‘: a += b; break; case ‘-‘: a -= b; break; case ‘*‘: a *= b; break; case ‘/‘: a /= b; break; } ch = getchar(); putchar(ch); } printf("%.3f\n", a); return 0; }
例如输入:1+2.5*3
输出:10.5
时间: 2024-09-30 23:58:23