void main()
{
int a[2][3]={ //定义数组放2月份的天数
{29,28}
};
int year,month; //定义年、月
printf("Please enter a year:\n"); //接受年份
scanf("%d",&year);
printf("Please enter a month:\n"); //接受月份
scanf("%d",&month);
if(1<=month<=12) //有效月份
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{ //一年中的31天的月份
printf("There are 31 days in the %d month of the %d\n",month,year);
}
else if(month==4||month==6||month==9||month==11)
{ //一年中30天的月份
printf("There are 30 days in the %d month of the %d\n",month,year);
}
else
{
if(year%400==0||year%4==0 && year%100!=0)
{ //闰年的2月份
a[0][1]=29;
printf("There are %d days in the %d month of the %d\n",a[0][0],month,year);
}
else
{ //平年的2月份
printf("There are %d days in the %d month of the %d\n",a[0][1],month,year);
}
}
}
else
{ //月份不在0~12的无效
printf("输入月份无效!\n");
}
}