C_在switch-case语句中使用exit()函数求非闰年的每月天数

来源:互联网 发布:会员数据分析报告 编辑:程序博客网 时间:2024/06/15 15:49

 源码:
# 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;
}
 
其中,若能按输入年份分为闰年和非闰年输出每月天数,可能更好。(待解决)

原创粉丝点击