已经编译运行确认过。
#include
#include
int leap(int); /*判断是否为闰年*/
int md(int m,int y); /*返回渗枯丛本月的天数*/
void prtweek(void); /*输出表头*/
int fw(int m,int y); /*返回本月一号是星期几败银*/
void prtmonth(int m); /*输出月份表头*/
int main(void)
{
int y,m,i,test,week;
printf("请输入您要查询的年份: ");
scanf("%d",&y);
for (m=1; m<丛樱=12; m++) {
test=1;
prtmonth(m);
prtweek();
week=fw(m,y);
if (week!=6)
for (i=0; i<=week; i++) {
putchar('\t');
test++;
}
for (i=1; i<=md(m,y); i++,test++) {
printf("%d\t",i);
if (test%7==0) {
putchar('\n');
}
}
putchar('\n');
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");
}
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;
}
}