| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
- #include <stdio.h>
 
  
- int main()
 
 - {        int i,j; 
 
 -         int birth_year,now_year;
 
 -         int birth_month,now_month;
 
 -         int birth_day,now_day;
 
 -         int count = 0;//计算总共活了多少天
 
 -         int day_month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
 
 -         
 
 -          
 
 -         
 
 -         printf("请输入你的生日(如1988-05-20):");
 
 -         scanf("%d-%d-%d",&birth_year,&birth_month,&birth_day);
 
 -         printf("请输入今天的日期(如2016-03-28):"); 
 
 -         scanf("%d-%d-%d",&now_year,&now_month,&now_day); 
 
 -         
 
 -         /*以生日1988-05-20今天是 2016-03-28为例,先算从1989年到2015年的所有天数
 
 -           再算出生月份加一月即6月到12月的天数加上5月天数减去出生的天数,加上2016年1月1日到3月28日
 
 -           的天数*/         
 
 -                 
 
 -         for(birth_year += 1;birth_year<=now_year-1;birth_year++)
 
 -         {
 
 -                 if(birth_year%4 == 0&&birth_year%100 != 0 ||birth_year%400==0)
 
 -                 {
 
 -                         day_month[1] = 29;
 
 -                         for(i=0;i<=11;i++)
 
 -                         {
 
 -                                 count += day_month[i];
 
 -                         }
 
 -                 }
 
 -                 else
 
 -                 {
 
 -                         for(i=0;i<=11;i++)
 
 -                         {
 
 -                                 count += day_month[i];
 
 -                         }        
 
 -                 }
 
 -         }
 
 -         if(birth_year%4 == 0&&birth_year%100 != 0 ||birth_year%400==0)
 
 -         {
 
 -                 day_month[1] = 29;
 
 -                 if (birth_month != 12)
 
 -                 {
 
 -                         for(j=birth_month;j<=12;j++)
 
 -                         {
 
 -                                 count += day_month[j-1];
 
 -                         }
 
 -                 }
 
 -                 count += day_month[birth_month-1] - birth_day;
 
 -         }
 
 -         else
 
 -         {
 
 -                 if (birth_month != 12)//如果出生日期是12月就不用算 
 
 -                 {
 
 -                         for(j=birth_month;j<=12;j++)
 
 -                         {
 
 -                                 count += day_month[j-1];
 
 -                         }
 
 -                 }
 
 -                 count += day_month[birth_month-1] - birth_day;//当前月份的天数减去剩下的天数                
 
 -         }
 
 -         
 
 -         if(now_year%4 == 0&&now_year%100 != 0 ||now_year%400==0) 
 
 -         {
 
 -                 day_month[1] = 29;
 
 -                 for(i = 1;i<=now_month;i++)
 
 -                 {
 
 -                         count += day_month[i-1];
 
 -                 }
 
 -                 count += birth_day; 
 
 -         }
 
 -         else
 
 -         {
 
 -                 for(i = 1; i<= now_month;i++)
 
 -                 {
 
 -                         count += day_month[i-1];
 
 -                 }
 
 -                 count += birth_day;        
 
 -         }
 
 -         
 
 -         printf("您一定度过了%d天,日子过得真快请好好珍惜!",count);
 
 -         
 
 -         
 
 -         return 0;
 
 - }
 
  复制代码 
 
 
 
计算出来的天数和实际天数始终不对,我枯了  感谢各位大佬的帮助
只要遇到闰年你就讲第二月永久改为29了,后面不是闰年的也按29算 
 
 
 |   
 
 
 
 |