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

不知道哪儿有错

#include <stdio.h>
int main()
{
    int n;
    int year = 2008;
    int month = 8;
    int day = 8;
    if( year%4 == 0)
    {
        switch(month)
        {
            case 1:n=day;
                    break;
            case 2:n=31+day;
                    break;
            case 3:n=31+28+day;
                    break;
            case 4:n=31+28+31+day;
                    break;
            case 5:n=31+28+31+30+day;
                    break;
            case 6:n=31+28+31+30+31+day;
                    break;
            case 7:n=31+28+31+30+31+30+day;
                    break;
            case 8:n=31+28+31+30+31+30+day+31;
                    break;
            case 9:n=31+28+31+30+31+30+day+31+31;
                    break;
            case 10:n=31+28+31+30+31+30+day+31+31+30;
                    break;
            case 11:n=31+28+31+30+31+30+day+31+31+30+31;
                    break;
            case 12:n=31+28+31+30+31+30+day+31+31+30+31+30;
                    break;
        }
    }
    else
    {
        switch(month)
        {
            case 1:n=day;
                    break;
            case 2:n=31+day;
                    break;
            case 3:n=31+29+day;
                    break;
            case 4:n=31+29+31+day;
                    break;
            case 5:n=31+29+31+30+day;
                    break;
            case 6:n=31+29+31+30+31+day;
                    break;
            case 7:n=31+29+31+30+31+30+day;
                    break;
            case 8:n=31+29+31+30+31+30+day+31;
                    break;
            case 9:n=31+29+31+30+31+30+day+31+31;
                    break;
            case 10:n=31+29+31+30+31+30+day+31+31+30;
                    break;
            case 11:n=31+29+31+30+31+30+day+31+31+30+31;
                    break;
            case 12:n=31+29+31+30+31+30+day+31+31+30+31+30;
                    break;
        }
    }
    printf("%d",n);
    return 0;
}

正在回答

1 回答

闰年的判断条件不对,应该是

if(((year%4==0)&&(year%100!=0))||(year%400==0))

你再试试


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

举报

0/150
提交
取消
C语言入门
  • 参与学习       926020    人
  • 解答问题       20793    个

C语言入门视频教程,带你进入编程世界的必修课-C语言

进入课程

不知道哪儿有错

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