问答详情
源自:4-17 switch与if语句的应用

怎么会是221天?

    int sum,flag;

    switch(month){

        case 1:sum = 0 ; break;

        case 2:sum = 0+31;break;

        case 3:sum = 0+31+28;break;

        case 4:sum = 0+31+28+31;break;

        case 5:sum = 0+31+28+31+30;break;

        case 6:sum = 0+31+28+31+30+31;break;

        case 7:sum = 0+31+28+31+30+31+30;break;

        case 8:sum = 0+31+28+31+30+31+30+31;break;

        case 9:sum = 0+31+28+31+30+31+30+31+31;break;

        case 10:sum = 0+31+28+31+30+31+30+31+31+30;break;

        case 11:sum = 0+31+28+31+30+31+30+31+31+30+31;break;

        case 12:sum = 0+31+28+31+30+31+30+31+31+30+31+30;break;

    }

    sum = sum+day;

    

    if(year%4==0){

        flag=1;

    }else{

        flag=0;

    }

    if(flag=1&&month>2){

        sum++;

    }

    printf("%d年的%d月%d日是该年的第%d天",year,month,day,sum);

 

return 0;

}


提问者:_lychee 2018-09-20 09:49

个回答

  • 慕虎1433750
    2018-09-20 11:43:56

    221,没毛病