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

为什么结果是220 不是221

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


提问者:晓___南神 2019-08-23 16:11

个回答

  • 慕移动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––