c语言实现
#include<stdio.h>
struct date
{
int year,month,day;
};
void main()
{
struct date today,term;
int yeardays =0,day;
printf("Enter year month day: "); //输入年月日
scanf("%d %d %d",&today.year,&today.month,&today.day);
term.month=12;
term.day=31;
for(term.year=1990;term.year<today.year;term.year++)
yeardays += days(term); //以结构变量term调用函数累计整年的天数
yeardays += days(today); //以结构变量today调用函数累计当年的天数
day = yeardays % 5; //取余计算星期几
if(day>0 && day<4)
printf("He is fashing.\n");
else
printf("He is sleeping.\n");
}
days(day) //计算从年初到day时的天数
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判断是否为闰年
lp = day.year%4 == 0 && day.year%100!=0 || day.year%400 ==0;
for(i=0;i<day.month;i++)
day.day += day_tab[lp][i];
return (day.day); //返回累计天数
}