【C语⾔】多路分⽀switch-case ⽐如判断名次
#include <stdio.h>
main()
{
int rank = 0;
printf("enter one numbers:");
scanf("%d",&rank);switch case判断字符串
switch(rank)
{
case 1:
printf("first\n");
break;
case 2:
printf("second\n");
break;
case 3:
printf("third\n");
break;
default:
printf("others\n");
break;
}
return 0;
}
注意每个case都接了⼀个break;如果不加break;case后的语句都会执⾏
#include <stdio.h>
main()
{
int rank = 0;
printf("enter one numbers:");
scanf("%d",&rank);
switch(rank)
{
case 1:
printf("first\n");
case 2:
printf("second\n");
case 3:
printf("third\n");
default:
printf("others\n");
}
return 0;
}