您的位置:首页 > 其它

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

2009-11-05 20:45 127 查看
 源码:

# 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 include input
相关文章推荐