源代码:
switch…case 的运用
#include <stdio.h>
int main()
{
float a, b;
char c;
printf("Please input two numbers(a and b):\n");
scanf("%f %f", &a, &b);
printf("Please input + or - or * or /:\n");
scanf(" %c", &c);
switch(c)
{
case '+':
printf("%.2f + %.2f = %.2f\n", a, b, a + b);
break;
case '-':
printf("%.2f - %.2f = %.2f\n", a, b, a - b);
break;
case '*':
printf("%.2f * %.2f = %.2f\n", a, b, a * b);
break;
case '/':
printf("%.2f / %.2f = %.2f\n", a, b, a / b);
break;
default:
printf("ERROR!EXIT!\n");
break;
}
return 0;
}