标准输入年月,打印要求的月天数,求改进!
#include<stdio.h>#define MONTHS 12
int run(int month);
int ping(int month);
int main(void){
int year,month;
printf("input year and month:\n");
scanf("%d %d",&year,&month);
if(year%4==0 && year%100!=0 || year%400==0)
run(month);
else
ping(month);
}
/*闰年*/
int run(int month){
int days[MONTHS]={31,28,31,30,31,30,31,31,30,31,30,31};
int ndays; ndays=days[month-1];
printf("Month %d has %2d days.\n",month,ndays);
return ;
}
/*平年*/
int ping(int month){
int days[MONTHS]={31,29,31,30,31,30,31,31,30,31,30,31};
int ndays; ndays=days[month-1];
printf("Month %d has %2d days.\n",month,ndays);
return ;
}
有很多都是重复的,怎么改进更效率点,