要计算包括1980年以前的年份,只需将i=1980改为i=1;
再改一下最后一部分就行;如:
#include<stdio.h>
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);
}
Get_Week(int y,int m,int d)
{
unsigned long nday=0;
int i=1;
while(i<y)
{
if(IsLeap(i)==1)
nday=nday+366;
else
nday=nday+365;
i++;
}
i=1;
while(i<m)
{
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:nday=nday+31;break;
case 4:
case 6:
case 9:
case 11:nday=nday+30;break;
case 2:
{
if(IsLeap(y)==1)
nday=nday+29;
else
nday=nday+28;
break;
}
}
i++;
}
nday=nday+d-1;
nday=nday%7;
switch(nday)
{
case 6:printf("Sunday\n");break;
case 0:printf("Monday\n");break;
case 1:printf("Tuesday\n");break;
case 2:printf("Wednesday\n");break;
case 3:printf("Thursday\n");break;
case 4:printf("Friday\n");break;
case 5:printf("Saturday\n");break;
}
}