答案:#include <stdio.h>
#include <stdlib.h>
int leap(int); //判断是否为闰年
int md(int m,int y); //返回本月的天数
void prtweek(void); //输出表头
int fw(int m,int y); //返回本月一号是星期几
void prtmonth(int m); //输出月份表头void prtweekEx(int left, int right);
void prtmonthEx(int m);
void prtday(int left, int right, int year);
int main(int argc, char* argv[])
{
int y, m;
printf("Year:");
scanf("%d", &y);
for(m=1; m<=12; m+=2)
{
prtmonthEx(m);
prtweekEx(1, 2);
prtday(m, m+1, y);
system("pause");
}
return 0;
}int leap(int y)
{
return (y%4==0&&y%100||y%400==0)?1:0;
}
int md(int m,int y)
{
int d;
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:d=31;break;
case 4:
case 6:
case 9:
case 11:d=30;break;
case 2:d=leap(y)?29:28;break;
}
return d;
}void prtweek(void)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n","Sun","Mon","Tue","Wed","Thur","Fri","Sat");
}void prtweekEx(int left, int right)
{
printf("Sun Mon Tue Wed Thu Fri Sat\t");
printf("Sun Mon Tue Wed Thu Fri Sat\n");
}int fw(int m,int y)
{
int f;
if (m<3) {
m+=12;
y--;
}
f=(1+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
return f;
}void prtmonth(int m)
{
switch (m) {
default:
case 1:puts("===January===");break;
case 2:puts("===February===");break;
case 3:puts("===March===");break;
case 4:puts("===April===");break;
case 5:puts("===May===");break;
case 6:puts("===June===");break;
case 7:puts("===July===");break;
case 8:puts("===August===");break;
case 9:puts("===September===");break;
case 10:puts("===October===");break;
case 11:puts("===November===");break;
case 12:puts("===December===");break;
}
}void prtmonthEx(int m)
{
switch (m) {
default:
case 1:printf("===January===");break;
case 2:printf("===February===");break;
case 3:printf("===March===");break;
case 4:printf("===April===");break;
case 5:printf("===May===");break;
case 6:printf("===June===");break;
case 7:printf("===July===");break;
case 8:printf("===August===");break;
case 9:printf("===September===");break;
case 10:printf("===October===");break;
case 11:printf("===November===");break;
case 12:printf("===December===");break;
}
printf("\t\t\t\t");switch (m+1) {
default:
case 1:printf("===January===");break;
case 2:printf("===February===");break;
case 3:printf("===March===");break;
case 4:printf("===April===");break;
case 5:printf("===May===");break;
case 6:printf("===June===");break;
case 7:printf("===July===");break;
case 8:printf("===August===");break;
case 9:printf("===September===");break;
case 10:printf("===October===");break;
case 11:printf("===November===");break;
case 12:printf("===December===");break;
}
printf("\n");
}void prtday(int left, int right, int year)
{
int i;
int dayshow_left = 0;
int dayshow_right = 0;
int first_left = fw(left, year)+1;
int first_right = fw(right, year)+1;//输出第1行左列
for(i=0; i<first_left; i++)
{
printf(" ");
}
for(i=0; i<7-first_left; i++)
{
if(10 > i+1)
{
printf("%d ", i+1);
}
else
{
printf("%d ", i+1);
}
dayshow_left++;
}
printf("\t");//输出第1行右列
for(i=0; i<first_right; i++)
{
printf(" ");
}
for(i=0; i<7-first_right; i++)
{
if(10 > i+1)
{
printf("%d ", i+1);
}
else
{
printf("%d ", i+1);
}
dayshow_right++;
}
printf("\n");//接下