int DayOfMonth(int year, int month)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
return 29;
}
else
{
return 28;
}
default:
return 0;
}
}
根据输入年月计算该月份的天数
最新推荐文章于 2024-04-15 18:21:43 发布
本文介绍了一个C语言函数intDayOfMonth,该函数接受年份和月份作为参数,返回该月的天数。它正确处理了普通月份、2月在平年和闰年的天数。通过判断年份是否为闰年来决定2月的天数。
1万+

被折叠的 条评论
为什么被折叠?



