对呀,楼主有没有把闰年算进去呀
#include<stdio.h>
main()
{
int year1,moth1,day1,sum1,leap1;
int year2,moth2,day2,sum2,leap2;
int i,leap3=0,sum3,sum4,sum;
scanf("%d/%d/%d,%d/%d/%d",&year1,&moth1,&day1,&year2,&moth2,&day2);
switch(moth1)
{
case 1:sum1=365;break;
case 2:sum1=334;break;
case 3:sum1=306;break;
case 4:sum1=275;break;
case 5:sum1=245;break;
case 6:sum1=214;break;
case 7:sum1=184;break;
case 8:sum1=153;break;
case 9:sum1=122;break;
case 10:sum1=92;break;
case 11:sum1=61;break;
case 12:sum1=31;break;
default:printf("error1\n");
}
sum1=sum1-day1;
if((year1/4==0&&year1/100!=0)||year1/400==0)
leap1=1;
else leap1=0;
if(leap1==1&&moth1<=2)
sum1=sum1+leap1; /*计算出剩下生日后在这1年还剩下多少天*/
switch(moth2)
{
case 1:sum2=0;break;
case 2:sum2=31;break;
case 3:sum2=59;break;
case 4:sum2=90;break;
case 5:sum2=120;break;
case 6:sum2=151;break;
case 7:sum2=181;break;
case 8:sum2=212;break;
case 9:sum2=243;break;
case 10:sum2=273;break;
case 11:sum2=304;break;
case 12:sum2=334;break;
default:printf("error2\n");
}
sum2=sum2+day2;
if((year2/4==0&&year2/100!=0)||year2/400==0)
leap2=1;
else leap2=0;
if(leap2==1&&moth2>=2)
sum2=sum2+leap2; /*计算出现在的日期在本年过了多少天*/
sum3=((year2)-(year1)-2)*365;/*计算出生日年到本年经过了几年的天数*/
sum=sum1+sum2+sum3;/*生日年剩下的天数+生日年到本年的天数+本年已经过了的天数*/
for(i=year1++;i<=year2--;i++)
{if((i/4==0&&i/100!=0)||i/400==0)
leap3++;
}
sum=sum+leap3; /*在加上生日年和本年之间的闰年天数,有几个闰年加几*/
printf("sum=%d",sum);
}