/*第一行的排列不与其应对应的星期数对齐*/
/*万年历*/
#include "stdio.h"
/*计算该天离该年元旦的天数*/
int get_days (year,month,date)
int year,month,date;
{
int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i;
int sum=0;
if (leap_year(year)) m[2]=29;
for (i=1;i<month;i++)
sum+=m[i];
sum+=date;
return sum;
}
/*判断是否为闰年*/
int leap_year (year)
int year;
{
int leap;
leap=0;
if (year/100==0&&year/400==0) leap=1;
if (year/100!=0&&year/4==0) leap=1;
return leap;
}
/*计算该日的星期数*/
int get_week(year,month,date)
int year,month,date;
{
int week;
week=(year-1)+(year-1)/100-(year-1)/400+(year-1)/1000;
week+=get_days(year,month,date);
week%=7;
return week;
}
/*输出日历*/
void calendar (year,month,date)
int year,month,date;
{
int i;
int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("%d.%d\n",year,month);
printf("***************************************\n");
printf("SUN MON TUE WED THU FRI SAT\n");
for (i=1;i<m[month];i++)
{
printf("%-6d",i);
if (get_week(year,month,i)==6)
printf("\n");
}
printf("\n***************************************\n");
}
/*mian*/
void main()
{
int year,month,date;
printf("Input year,month,date as XX.XX.XX\n");
scanf("%d.%d.%d",&year,&month,&date);
printf("\n");
calendar(year,month,date);
}