谁能帮我做一下吗?要用winTC

12、三天打鱼两天晒网
中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日开始“三天打鱼两天晒网”,问这个人在以后的某一天是在“打鱼”,还中在“晒网”。由用户输入日期,要求用结构体表示日期(年,月,日)。

举手之劳,弄了算了。
一个完整的c程序如下,win-tc和Dev-c++下运行通过(英文为本人翻译)。
#include<stdio.h>
struct date{
int year;
int month;
int day;
};
int days(struct date day);

void main()
{
struct date today,term;
int yearday,year,day;
puts("***********************************************************************");
puts("* Fishing or idling ? *");
puts("* As the famous Chinese saying goes:fishing 3 days and idling 2 days *");
puts("* someone at age of 20 from 1990 1 1 begin fishing and idling *");
puts("* find one day after 1990 1 1 he is fishing or idling *");
puts("***********************************************************************\n");
while(1)
{
printf("\n\nPlease input year month and day (input 1990 1 1 to exit):");
scanf("%d%d%d",&today.year,&today.month,&today.day); /*输入日期*/
if(today.year<1990)
{
if(today.year<1970)
puts("Sorry,he wasn't born at that time. Strike any key to continue.");
else
puts("Sorry,he didn't begin fishing at that time. Strike any key to continue.");
getch();
continue;
}
if(today.year==1990&&today.month==1&&today.day==1)
break;
term.month=12; /*设置变量的初始值:月*/
term.day=31; /*设置变量的初始值:日*/
for(yearday=0,year=1990;year<today.year;year++)
{
term.year=year;
yearday+=days(term); /*计算从1990年至指定年的前一年共有多少天*/
}
yearday+=days(today); /*加上指定年中到指定日期的天数*/
day=yearday%5; /*求余数*/
if(day>0&&day<4) printf("%d %d %d he was fishing.\n",today.year,today.month,today.day); /*打印结果*/
else printf("%d %d %d he was idling.\n",today.year,today.month,today.day);

}
puts("\nStrike any key to quit.");
getch();
}

int days(struct date day)
{
static int day_tab[2][13]=
{{0,31,28,31,30,31,30,31,31,30,31,30,31,}, /*平均每月的天数*/
{0,31,29,31,30,31,30,31,31,30,31,30,31,},
};
int i,lp;
lp=day.year%4==0&&day.year%100!=0||day.year%400==0;
/*判定year为闰年还是平年,lp=0为平年,非0为闰年*/
for(i=1;i<day.month;i++) /*计算本年中自1月1日起的天数*/
day.day+=day_tab[lp][i];
return day.day;
}
温馨提示:答案为网友推荐,仅供参考
相似回答