题解 | #竞选社长#
简单计算器
http://www.nowcoder.com/practice/b8f770674ba7468bb0a0efcc2aa3a239
#include<stdio.h> int main() { double a = 0.0; double b = 0.0; char c ='0'; scanf("%lf %c %lf",&a,&c,&b); { switch (c) { case '+': printf("%.4lf+%.4lf=%.4lf",a,b,a+b); break; case '-': printf("%.4lf-%.4lf=%.4lf",a,b,a-b); break; case '': printf("%.4lf%.4lf=%.4lf",a,b,a*b); break; case '/': if(b == 0.0) { printf("Wrong!Division by zero!"); } else printf("%.4lf/%.4lf=%.4lf",a,b,a/b); break; default: printf("Invalid operation!"); break; } } return 0; }
#include<stdio.h> int main() { double a = 0.0; double b = 0.0; char c ='0'; scanf("%lf %c %lf",&a,&c,&b);
{
switch (c)
{
case '+':
printf("%.4lf+%.4lf=%.4lf",a,b,a+b);
break;
case '-':
printf("%.4lf-%.4lf=%.4lf",a,b,a-b);
break;
case '*':
printf("%.4lf*%.4lf=%.4lf",a,b,a*b);
break;
case '/':
if(b == 0.0)
{
printf("Wrong!Division by zero!");
}
else
printf("%.4lf/%.4lf=%.4lf",a,b,a/b);
break;
default:
printf("Invalid operation!");
break;
}
}
return 0;
}