|
20鱼币
#include <stdio.h>
int main()
{
int w,c,y,Y,m,M,d,ret;
printf("请输入查询日期:格式为yyyy-mm-dd ");
ret=scanf("%4d-%2d-%2d",&Y,&m,&d);
if (ret != 3)
printf("请输入正确的格式!");
else if(m>= 3 && m<= 12)
{
c= Y/100;
y= Y%100;
w= (y+y/4+c/4-2*c+26*(m+1)/10+d-1)%7;
switch(w)
{
case 1: printf("%4d-%2d-%2d是星期一",Y,m,d);break;
case 2: printf("%4d-%2d-%2d是星期二",Y,m,d);break;
case 3: printf("%4d-%2d-%2d是星期三",Y,m,d);break;
case 4: printf("%4d-%2d-%2d是星期四",Y,m,d);break;
case 5: printf("%4d-%2d-%2d是星期五",Y,m,d);break;
case 6: printf("%4d-%2d-%2d是星期六",Y,m,d);break;
case 7: printf("%4d-%2d-%2d是星期日",Y,m,d);break;
}
}
问题如图,请大家帮忙指正、解答,谢谢!
else if(m == 1||m == 2)
{
y= (Y-1)%100;
c= (Y/100);
M= m+12;
w= (y+ y/4+ c/4-2*c+ 26*(M+ 1)/10+ d-1)%7;
switch(w)
{
case 1: printf("%4d-%2d-%2d是星期一",Y,m,d);break;
case 2: printf("%4d-%2d-%2d是星期二",Y,m,d);break;
case 3: printf("%4d-%2d-%2d是星期三",Y,m,d);break;
case 4: printf("%4d-%2d-%2d是星期四",Y,m,d);break;
case 5: printf("%4d-%2d-%2d是星期五",Y,m,d);break;
case 6: printf("%4d-%2d-%2d是星期六",Y,m,d);break;
case 7: printf("%4d-%2d-%2d是星期日",Y,m,d);break;
}
}
return 0;
}
#include <stdio.h>
int main()
{
int w,c,y,Y,m,d,M,ret;
printf("请输入查询日期:格式为yyyy-mm-dd ");
ret=scanf("%4d-%2d-%2d",&Y,&m,&d);
if(ret != 3)
printf("请输入正确的格式!");
else
if(m>= 3 && m<= 12)
{
c= Y/100;
y= Y%100;
w= (y+y/4+c/4-(2*c)+26*(m+1)/10+d-1)%7;
switch(w)
{
case 0: printf("%4d-%2d-%2d是星期日",Y,m,d);break;
case 1: printf("%4d-%2d-%2d是星期一",Y,m,d);break;
case 2: printf("%4d-%2d-%2d是星期二",Y,m,d);break;
case 3: printf("%4d-%2d-%2d是星期三",Y,m,d);break;
case 4: printf("%4d-%2d-%2d是星期四",Y,m,d);break;
case 5: printf("%4d-%2d-%2d是星期五",Y,m,d);break;
case 6: printf("%4d-%2d-%2d是星期六",Y,m,d);break;
}
}
else if(m== 1|| m== 2)
{
M= m+12;
y= (Y-1)%100;
c= (Y-1)/100;
w= (y+ y/4+ c/4-(2*c)+ 26*(M+ 1)/10+ d-1)%7;
switch(w)
{
case 0: printf("%4d-%2d-%2d是星期日",Y,m,d);break;
case 1: printf("%4d-%2d-%2d是星期一",Y,m,d);break;
case 2: printf("%4d-%2d-%2d是星期二",Y,m,d);break;
case 3: printf("%4d-%2d-%2d是星期三",Y,m,d);break;
case 4: printf("%4d-%2d-%2d是星期四",Y,m,d);break;
case 5: printf("%4d-%2d-%2d是星期五",Y,m,d);break;
case 6: printf("%4d-%2d-%2d是星期六",Y,m,d);break;
}
}
return 0;
}
|
|