假如某月的1日是星期三,那么输入该月中的日期,要求输出对应的星期数。如输入3,则输出Friday。(用if…else…与switch语句两种方法实现)。
#include<stdio.h>
int main()
{
int day = 0;
scanf (“%d”, &day);
int week = (day + 2) % 7;
switch (week)
{
case 0:
printf(“Sunday\n”);
break;
case 1:
printf(“Monday\n”);
break;
case 2:
printf(“Tuesday\n”);
break;
case 3:
printf(“Wednesday\n”);
break;
case 4:
printf(“Thursday\n”);
break;
case 5:
printf(“Friday\n”);
break;
case 6:
printf(“Saturday\n”);
break;
}
return 0;
}
在这里插入代码片
```#include<stdio.h>
int main()
{
int day = 0;
scanf (“%d”, &day);
int week = (day + 2) % 7;
switch (week)
{
case 0:
printf(“Sunday\n”);
break;
case 1:
printf(“Monday\n”);
break;
case 2:
printf(“Tuesday\n”);
break;
case 3:
printf(“Wednesday\n”);
break;
case 4:
printf(“Thursday\n”);
break;
case 5:
printf(“Friday\n”);
break;
case 6:
printf(“Saturday\n”);
break;
}
return 0;
}