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

它说 else (year%4==0&&month==2) { day+=29; }错了,我看了好几遍不知道哪里错了,求大神指点

#include <stdio.h>

int main() 

 

    int year = 2008;

    int month = 8;

    int day = 8;

  

    

    for(month=1;month<8;month++)

     { 

         if (month==1||3||5||7)

        {

         day+=31;

        }

        else (year%4==0&&month==2)

        {

         day+=29;   

        }

        else if(month==4||6)

        {

         day+=30;

        }

      

        

     }

    

    printf("2008年8月8日是该年的第%d\n天",day);









return 0;

}


正在回答

1 回答

兄弟你这个优先级就错了,比如(year%4==0&&month==2)先执行year%4==0,这个结果是1,同时执行month==2,比如第一轮for循环month=1那month==2结果为0,然后执行&&,就是1&&0,结果出0,在else括号里就不是一个条件了就运行不了{}里的代码


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

举报

0/150
提交
取消

它说 else (year%4==0&&month==2) { day+=29; }错了,我看了好几遍不知道哪里错了,求大神指点

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信