源码:
# include <stdlib.h>
# include <stdio.h>
int main()
{
int month;
int day;
printf("please input the month number: ");
scanf("%d", &month);
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day=31; // 有31天的月份情况
break;
case 4:
case 6:
case 9:
case 11: day=30; // 有30天的月份的情况
break;
case 2: day=28; // 非闰年的2月有28天
break;
default: exit(0);
}
printf("1999.%d has %d days./n", month, day);
return 0;
}
其中,若能按输入年份分为闰年和非闰年输出每月天数,可能更好。(待解决)
C_在switch-case语句中使用exit()函数求非闰年的每月天数
最新推荐文章于 2022-03-09 17:40:16 发布