一个关于switch 的运用
输入a+(或-或*或/)b,并运算相应结果
#include<stdio.h>
int main()
{
int a, b, r;
double s;
char ch;
printf("a运算符b:");
scanf_s("%d%c%d", &a, &ch, 1, &b);
switch (ch)
{
case '+':
r = a + b;
printf("a + b=%d", r);
break;
case '-':
r = a - b;
printf("a - b=%d", r);
break;
case '*':
r = a * b;
printf("a * b=%d", r);
break;
case'/':
if (b != 0)
{
s = a * 1.0 / b;
printf("a/b=%lf", s);
}
else
printf("除数为零!!!!!");
break;
}
return 0;
}