#include <stdio.h>
#include <conio.h>
int main(void)
{
int year,dayextra,q,day;
printf("enter the year");
scanf("%d",&year);
year=year-1;
q=year/4;
dayextra=year+q;
day=dayextra%7;
switch(day)
{
case '3':printf("\nmonday");
break;
case '4':printf("\ntuesday");
break;
case '5':printf("\nwed");
break;
case '6':printf("\nthu");
break;
case '7':printf("\nfri");
break;
case '1':printf("\nsat");
break;
case '2':printf("\nsun");
break;
}
getch();
}
最佳答案
case '3'
正在测试 day
是否等于 3
字符的 ASCII 值(即 63)。day
不可能具有值 63。请尝试使用 case 3
代替。这同样适用于您的所有其他案例。
我自己的测试表明,case 0
应该是周日,case 1
应该是周一,依此类推,直到 case 6
是周六.
关于c - 程序查找 01 到 99 年 1 月 1 日的日子; switch 语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7055397/