case条件选择语句 具体例题
switch-case的简单计算器
#include <stdio.h>
int main( )
{
double a, b;
char op;
scanf("%lf%c%lf", &a, &op, &b);
switch (op)
{
case '+':
printf("%lf + %lf = %lf\n", a, b, a + b);
break;
case '-':
printf("%lf - %lf = %lf\n", a, b, a - b);
break;
case '*':
printf("%lf * %lf = %lf\n", a, b, a * b);
break;
case '/':
if (b != 0)
printf("%lf / %lf = %lf\n", a, b, a / b);
else
printf("除数不能是0! \n");
break;
}
}