编写程序,根据给定的年分与月份,判断该年是否闰年
编写程序,根据给定的年分与月份,判断该年是否闰年,并根据月份来判断是什么季节以及该月的天数。闰年的判断条件是能被400整除或者能被4整除但不能被100整除。...
编写程序,根据给定的年分与月份,判断该年是否闰年,并根据月份来判断是什么季节以及该月的天数。闰年的判断条件是能被400整除或者能被4整除但不能被100整除。
展开
展开全部
#include<stdio.h>
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);
}
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);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询