开关语句switch(变量)
switch(weekday)
↓
数字
default:异常处理
case-break
#include <stdio.h>
int main()
{
int weekday=3;
switch(weekday)
{
case 1:
printf("today is Monday\n");
break;
case 2:
printf("today is Tuesday\n");
break;
case 3:
printf("today is Wednesday\n");
break;
case 4:
printf("today is Thursday\n");
break;
case 5:
printf("today is Friday\n");
break;
case 6:
printf("today is Saturday\n");
break;
case 7:
printf("today is Sunday\n");
break;
default:
printf("You write the wrong number!");
break;
}
return 0;
}
时间: 2024-10-27 06:40:18