case条件选择语句
case条件选择语句 具体例题
case条件选择语句 具体例题
2018-03-20
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;
}
}
举报