先谢谢5楼的朋友,麻烦你再看一下哪里的修改,运行时1980年1月1日是星期三而不是
星期二,而2006年7月15日却是星期1,正确应该是星期六.
main()
{
int a,b,c;
printf("\nPlease input year,month,day:");
scanf("%d,%d,%d",&a,&b,&c);
printf("%d-%d-%d is ",a,b,c);
Get_Week(a,b,c);
getch();
}
int IsLeap(int year)
{
if(year%4==0&&year%100!=0||year%400==0)
return(1);
return(0);
}
int Get_Week(int y,int m,int d)
{
long nday=0;
int i=1980;
for(i=1980;i<y;i++)
{
if(IsLeap(i)==1)
nday+=366;
else
nday+=365;
}
while(i<m)
{
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:nday+=31;break;
case 4:
case 6:
case 9:
case 11:nday+=30;break;
case 2:
{
if(IsLeap(y)==1)
nday+=29;
else
nday+=28;
break;
}
}
}
nday+=d;
switch(nday%7)
{
case 5:printf("Sunday\n");break;
case 6:printf("Monday\n");break;
case 0:printf("Tuesday\n");break;
case 1:printf("Wednesday\n");break;
case 2:printf("Thursday\n");break;
case 3:printf("Friday\n");break;
case 4:printf("Saturday\n");break;
}
}