#include<stdio.h>
void printf_calendar(int year,int month,int days,int data);
int data_of_month(int year,int month);
int day_of_month(int year,int month,int t);
int is_runyear(int year);
void main_func(int year,int month);
int main(){ /*采用分支法,主函数最好简单*/
int year,month;
scanf("%d%d",&year,&month);
main_func(year,month);
return 0;
}
void main_func(int year,int month) /*主体函数*/
{
int t,data,days;
t=is_runyear(year);/*判断是否闰年*/
days=day_of_month(year,month,t);/*判断某月有多少天*/
data=data_of_month(year,month);/*计算该月第一天是星期几*/
printf_calendar(year,month,days,data); /*打印函数*/
}
int is_runyear(int year){
int t=0;
//t=all_days();
if( year%4==0 && year%400==0 && year%100!=0){return 1;}
else return 0;/*返回 是不是闰年,1-是,0-不是*/
}
int day_of_month(int year,int month,int t){
int days=0;
if (month==1 || month==3 ||month==5 ||month==7 ||month==8 ||month==10 ||month==12 )
days=31;
else if( month==4||month==6 ||month==9 || month==11 )
days=30;
else
if(t==1){days=29;}
else if(t==0)days=28;
return days;
}
int data_of_month(int year,int month){
int y0,m0,d0,x;
int day=1;
y0=year-(14-month)/12;
x=y0+y0/4-y0/100+y0/400;
m0=month+12*((14-month)/12)-2;
d0=(day+x+(31*m0)/12)%7;
return d0;/*返回星期几*/
}
void printf_calendar(int year,int month,int days,int data){
int i;
printf("'\t\t%dyear%dmonth\n",year,month);
printf("Sun\tMon\tFbur\tWed\tThur\tFri\tSatu\n");
for(i=1;i<data;i++){
printf("\t\t");/*打印前面几个空格*/
}
for(i=1;i<=days;i++){
printf("%d\t",i);
if((data+i)%7==0)printf("\n");
}/*打印月历*/
}