这样修改,就可以运行了
#include<stdio.h>
#include<stdlib.h>
int monthday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
/*数组monthday[13]存放每个月的天数*/
char monthname[13][6]={"","JAN","FEB","MAR","APR","MAY","JUNE",
"JULY","AUG","SEP","OCT","NOV","DEC"};
/*数组monthname[][]存放每个月的英文名称,用于打印*/
/*char weekday[8][6]={"SUN","MAN","TUE","WED","THU","FRI","SAT","SUN"};*/
char weekday[8][9]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
/*数组weekday[][]存放一周的每一天的英文名称,用于打印*/
int month2[6][7];
int leapyear(int year)
/*函数1:判断year是否为闰年*/
{if((year%4==0)&&(year%100)!=0||(year%400)==0)
return 1;
else
return 0;
}
void print2(int month,int t)
/*函数2:按月打印日历*/
{ int i,j;
printf("*** %s ***\n",monthname[month]);
for(i=0;i<=6;i++)
printf("%-8s",weekday[i]);
printf("\n");
for(i=0;i<=t;i++)
{for(j=0;j<=6;j++)
if(month2[i][j]==0)
printf("%8s"," ");//printf(" ");
else
printf("%3s%-5d"," ",month2[i][j]);
printf("\n");
}
}
void calendar(int year)
/*函数3:主体函数,按月生成日历*/
{int month;
int todayweek,today,i,j,t;
if(leapyear(year))
monthday[2]=29;
else
monthday[2]=28;
todayweek=year+(year-1)/4-(year-1)/100+(year-1)/400;
todayweek=todayweek%7;
/*计算当年第1天是星期几*/
printf("=== year %d ===\n",year);
for(month=1;month<=12;month++)
{today=1;
for(i=0;i<=5;i++)
for(j=0;j<=6;j++)
month2[i][j]=0;/*清空*/
t=0;
while(today<=monthday[month])
{month2[t][todayweek]=today;
todayweek++; today++;
if(todayweek==7)
{todayweek=0;
t++;
}
}
print2(month,t);
}
}
main()
{int year;
printf("请输入年份:\n");
scanf("%d",&year);
printf(" 一切有为法,如梦幻泡影,如露亦如电,应作如是观。\n\n");
calendar(year);
system("pause");
}