为了账号安全,请及时绑定邮箱和手机立即绑定

为什麽switch后面条件month要-1?

#include <stdio.h>
int main()
{
    int year = 2008;
    int month = 8;
    int day = 8;
    switch(month-1)
    {
        case 12:day+=31;
        case 11:day+=30;
        case 10:day+=31;
        case 9:day+=30;
        case 8:day+=31;
        case 7:day+=31;
        case 6:day+=30;
        case 5:day+=31;
        case 4:day+=30;
        case 3:day+=31;
        case 2:if((year%4==0 && year%100!=0) || year%400==0)
                    day+=29;
               else
                    day+=28;
        case 1:day+=31;
    }
    printf("2008年8月8日是该年的第%d天",day);
 return 0;
}

正在回答

1 回答

首先,不加break会顺序执行接下来的代码,再有就是,假设,今天是8月8号,8月其实只过了8天,前面七个月是真正过完了的......

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什麽switch后面条件month要-1?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号