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

#include <stdio.h> int main() { int year = 2008; int month = 8; int day = 8; int sum=0; switch(month) { case 1:sum=sum+day;break; case 2:sum=sum+day+31;break; case 3:sum=sum+day+31+28;break; case 4:sum=sum+

#include <stdio.h>

int main() 

{

    int year = 2008;

    int month = 8;

    int day = 8;

    int sum=0;

    switch(month)

    {

      case 1:sum=sum+day;break;

      case 2:sum=sum+day+31;break;

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

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

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

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

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

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

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

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

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

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

    }

    

    if((year%400==0)||(year%4==0&&year%100!=0)){printf("%d年%d月%d日是该年的第%d天",year,month,day,sum+1);}

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

    

    

return 0;


提问者:我的仰视30 2015-04-19 04:37

个回答

  • Perona
    2015-12-13 00:01:02

    又见楼主