#include <stdio.h>
#include <math.h> int leap_year(int year){
if(year%== || (year%== && year%!=)){
return ;//是闰年
}else{
return ;//不是闰年
}
} int mon_d(int year,int mon){
int i, days = ,mon_days[] = {,,,,,,,,,,,};
//for(i=1;i<mon;i++){
if(mon >= ){
if(leap_year(year) == ){
mon_days[] = ;
for(i=; i<mon-; i++){
days += mon_days[i];
}
return days;
}else{
for(i=;i < mon-;i++){
days += mon_days[i]; }
return days;
}
}
//}
return ;
} int main(){ int y1, m1, d1, y2, m2, d2, i, y, day_to_day = ;
printf("请您输入一个日期(eg:2008-8-8): "); scanf("%d-%d-%d",&y1,&m1,&d1); printf("请您再输入一个日期(eg:2008-8-8): ");
scanf("%d-%d-%d",&y2,&m2,&d2);
//printf("%d-%d-%d\n",y1,m1,d1);
//printf("%d-%d-%d\n",y2,m2,d2); y = y2-y1; if(y == ){
day_to_day = mon_d(y2,m2) + d2 - (mon_d(y1,m1) + d1);
}else if(y == ){
day_to_day = + leap_year(y1) - ( mon_d(y1,m1) + d1 ) + mon_d(y2,m2) +d2;
}else{
for(i=y1+; i<y2; i++){
day_to_day += + leap_year(i);
}
day_to_day += + leap_year(y1) - ( mon_d(y1,m1) + d1 ) + mon_d(y2,m2) +d2;;
}
printf("这两个日期相差的天数是: %d 天\n",day_to_day); }