#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+

来源:4-17 switch与if语句的应用

我的仰视30

2015-04-19 04:37

#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;


写回答 关注

1回答

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

    又见楼主

C语言入门

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

926020 学习 · 20793 问题

查看课程

相似问题