为什么结果是220 不是221

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

晓___南神

2019-08-23 16:11

#include <stdio.h>
int main() { 
    /* 定义需要计算的日期 */   
     int year = 2008;  
     int month = 8; 
         int day = 8;
          int sumDay = 0;    /* 
                             
          do
          {        
              month--;        
              switch(month)        
              {            
                  case 1:            
                  case 3:            
                  case 5:            
                  case 7:            
                  case 8:            
                  case 10:            
                  case 12:                
                      sumDay += 31;                
                  break;
                              
                  case 2:                
                      if(year %4 == 0)                
                      {                    
                      sumDay += 28;                
                      }
                      else
                      {                     
                      sumDay += 27;                
                      }                
                  break;            
                  default:
                      sumDay += 30; 
                  break;                
        }
                  printf("月份%d\n",month);
                  printf("%d\n",sumDay);
              }while(month >= 2); 
              sumDay += day ;
              printf("%d\n",sumDay);
          
          return 0;}


写回答 关注

3回答

  • 慕移动8513986
    2019-08-24 00:49:49
    已采纳

    2月闰年有29天,平年28天。你写错了

  • 煌璃瞻
    2019-09-02 21:49:32

    这个可以输出8月的?

  • 慕勒2399010
    2019-08-29 17:52:08

    想问一下为什么要加do和那个month––

C语言入门

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

926206 学习 · 20797 问题

查看课程

相似问题