----------------解决方案--------------------------------------------------------
int IsLeap(int year)//判断是否为闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return(1);
return(0);
}
void Get_Week(int y,int m,int d)
{
long nday=0;
int i=1980;
while(i<y)//处理年份
{
if(IsLeap(i)==1)
nday+=366;
else
nday+=365;
i++;
}
i=1;
while(i<m)//处理月份
{
switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:dayn+=31;break;
case 4:
case 6:
case 9:
case 11:dayn+=30;break;
case 2:
{
if(IsLeap(y)==1)
nday+=29;
else
nday+=28;
break;
}
}
}
nday+=d;//处理天数
switch(nday%7)//总天数对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;
}
}
/*直接在Get_Week输出星期,不知道是否满足楼主的要求,程序尚未调式,请楼主调试一下,大概思想就是这样的,呵呵*/
----------------解决方案--------------------------------------------------------
在Get_Week()函数调用前加个printf("\n%d-%d-%d is",a,b,c);就OK 了
----------------解决方案--------------------------------------------------------
先谢谢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;
}
}
----------------解决方案--------------------------------------------------------
#include<stdio.h>
int IsLeap(int year)//判断是否为闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return(1);
return(0);
}
void Get_Week(int y,int m,int d)
{
long nday=0;
int i=1980;
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)//总天数对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;
}
}
int main()
{
int a,b,c;
printf("\nPlease input year,month,day:");
scanf("%d%d%d",&a,&b,&c);
printf("\n%d-%d-%d is week ",a,b,c);
Get_Week(a,b,c);
return(0);
}
/*我已经调试过了,可以满足楼主的要求*/
----------------解决方案--------------------------------------------------------
不好意思上次没有调试,所以忽律了一些细节.
----------------解决方案--------------------------------------------------------
那这个程序只能算出1980以后的日子咯?
对吗?
----------------解决方案--------------------------------------------------------