第五章指针
题目:三天打鱼两天晒网,输入一个日期,从2000第一天开始计算该天是晒网还是打鱼?
#include<stdio.h>
int main()
{
struct date
{
int year;
int month;
int day;
};
struct date today;
struct date *p_today=0;
static int day_tab[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
int i;
int flag=0;
unsigned int day=0;
int year;
p_today=&today;
printf("请输入待查询的日期(年,月,日):");
scanf("%d,%d,%d",&p_today->year,&p_today->month,&p_today->day);
flag=(p_today->year%4==0&&p_today->year%100!=0||p_today->year%400==0);
for(i=0;i<p_today->month-1;i++)day=day+day_tab[flag][i];
day=day+p_today->day;
for(year=2000;year<p_today->year;year++)
{
flag=(year%4==0&&year%100!=0||year%400==0);
for(i=0;i<12;i++)day=day+day_tab[flag][i];
}
if(day%5>0&&day%5<4)printf("该天该打鱼");
else printf("该天该晒网");
return 1;
}