# include <stdio.h>
# include <windows.h>
int main(void)
{
int year, mouth, week;
int dis_year, dis_mouth, distance;
int mouths[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int i, j, t;
printf("请输入日期(格式:1900-01):\n");
scanf("%d-%d", &year, &mouth);
/*得到那个月份1号为周几(详见: [输出星期.cpp])*/
dis_year = year - 1900;
i = dis_year % 4;
j = dis_year / 4;
dis_year = j*1461 + i*365;
dis_mouth = 0;
for (i=1; i<mouth; i++)
dis_mouth += mouths[i-1];
if (mouth > 2 && year%4 == 0)
dis_mouth += 1;
distance = 0;
distance = dis_year + dis_mouth;
week = (1+distance) % 7;
system("CLS");
/*控制输出*/
printf("
%d年%d月\n\n", year, mouth);
printf(" 日
一
二
三
四
五
六\n");
//表头
for (i=0; i<week; i++)
printf("
");
//空出不是本月的地方
i=week;
if (year%4 == 0)
mouths[1] += 1;
for (t=1; t<=mouths[mouth-1]; t++)
//输出这个月的每天
{
if (7 == i)
{
printf("\n");
i = 0;
}
//通过i控制换行
printf("%3d ", t);
i++;
}
printf("\n");
return 0;
}