编写程序,根据给定的年分与月份,判断该年是否闰年

2024-12-16 16:01:34
推荐回答(1个)
回答1:

#include
bool IsLeap(int year){
return ( year % 400 == 0 || (year % 4 == 0 && year % 100 != 0) );
}
void season(int month){
switch (month )
{
case 3:
case 4:
case 5:
printf("春季");
break;
case 6:
case 7:
case 8:
printf("夏季");
break;
case 9:
case 10:
case 11:
printf("秋季");
break;
case 1:
case 2:
case 12:
printf("冬季");
break;
default:
printf("输入错误!");
break;
}
}
int days(int year,int month){
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
break;
case 4:
case 6:
case 9:
case 11:
return 30;
break;
case 2:
if (IsLeap(year))
return 29;
return 28;
break;
default:
printf("输入错误!");
return -1;
break;
}
}
void main(){
int year,month;
printf("请输入年份 月份:");
scanf("%d%d",&year,&month);
if (IsLeap(year))
printf("%d年是闰年 ",year);
else
printf("%d年是平年 ",year);
printf("%d月%d天 是",month,days(year,month));
season(month);
}