/*忘了写此程序的有效期是1900年后,有好多可能没有写明白 */
#include
#include
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}};
struct date {
int year;
int month;
int day;
};
int days(struct date day)
{
int i,lp;
lp=day.year%4==0&&day.year%100!=0||day.year%400==0;
/* lp 非0为闰年*/
for(i=1;i day.day+=day_tab[lp][i]; /*计算本年中1月1日起的天数*/
return(day.day);
}
int main()
{ struct date today,term;
int year,day,i,x,j;
unsigned int yearday;
while (1){
printf("\nEnter year/month/day:");
scanf("%d/%d/%d",&today.year,&today.month,&today.day);
//monthday=today.day
term.month=12;
term.day=31;
for (yearday=0,year=1900;year { term.year=year;
yearday +=days(term); /*计算今年前的总天数*/
}
yearday +=days(today)-today.day+1;
day=yearday%7; /*算这个月1日是星期几*/
//printf(" This date is %ds ",day);
x= today.year%4==0&&today.year%100!=0||today.year%400==0;
if(today.year<1900 ||today.month<1||today.month>12||today.day<1 ||today.day>day_tab[x][today.month])
{ printf("输入的日期格式错误\n");
exit(1);
}
printf("------------------------------\n");
printf(" Sun Mon Tue Wed Thu Fri Sat \n"); /*打印日历*/
for(j=0;j for(++j,i=1;i<=day_tab[x][today.month];i++,j++) /*打印当月的总天数*/
{ /* if (i==today.day) printf(" \1 ");
else*/
printf("%4d",i);
if (j%7==0) printf("\n"); /*控制日历格式打印*/
}
printf("\n");
}
return 0;
}
阅读(1937) | 评论(2) | 转发(0) |