C语言中switch只支持int和char类型,float之类的就要用if,如果你用的是float例如:
#include <stdio.h>
int main()
{
float a;
printf (“a:”);
scanf("%f",&a); //a是float型
switch(a) {
case 1: printf(“a”); break;
case 2: printf(“b”); break;
}
return 0;
}
这里用的是float,如果再用switch就会报错。