需要注意一点就是 需要double类型,最后一个测试题才能精度准确
#include<stdio.h> int main() { double a,b; char c; scanf("%lf%c%lf",&a,&c,&b); if(c!='+'&&c!='-'&&c!='*'&&c!='/') printf("Invalid operation!\n"); else if(c=='+') printf("%.4lf+%.4lf=%.4lf",a,b,a+b); else if(c=='-') printf("%.4lf-%.4lf=%.4lf",a,b,a-b); else if(c=='*') printf("%.4lf*%.4lf=%.4lf",a,b,a*b); else if(c=='/') { if(b==0.0) printf("Wrong!Division by zero!\n"); else printf("%.4lf/%.4lf=%.4lf",a,b,a/b); } return 0; }