#includeintleap(intyear){if(year%4==0&&year%100!=0||year%400==0)//判断是否是闰年return1;elsereturn0;}intdays_month(intmonth,intyear)//判断大月和小月{if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)//找出大月return31;if(month==4||month==6||month==9||month==11)//找出小月return30;if(month==2&&leap(year)==1)return29;//判断二月是29天还是29天elsereturn28;}intfirstday(intmonth,intyear){intw;w=(1+2*month+3*(month+1)/5+year+year/4+year/400-year/100)%7+1;//判断每个月开始的第一天是星期几returnw;}main(){inti,j=1,k=1,a,b,month,year;printf(\\"inputmonthandyear:\\");scanf(\\"%d%d\\",&month,&year);//输入月和年b=days_month(month,year);a=firstday(month,year);printf(\\"SunMonTueWedThuFriSat\\");//输出对应当月的日历if(a==7){for(i=1;i<=b;i++){printf(\\"%4d\\",i);if(i%7==0){printf(\\"\\");}}}if(a!=7){while(j<=4*a){printf(\\"\\");j++;}for(i=1;i<=b;i++){printf(\\"%4d\\",i);if(i==7*k-a){printf(\\"\\");k++;}}}printf(\\"\\");}