#include <stdio.h>
int main(void){
int year1, month1, day1, midDay;
int year2, month2, day2;
int totalDate1;
int totalDate2;
printf("请输入两个日期 年 月 日
");
scanf("%d%d%d", &year1, &month1, &day1);
printf("%d,%d,%d
", year1, month1, day1);
printf("
");
scanf("%d%d%d", &year2, &month2, &day2);
printf("%d,%d,%d
", year2, month2, day2);
switch(month1){
case 1:totalDate1=day1;break;
case 2:totalDate1=31+day1;break;
case 3:totalDate1=59+day1;break;
case 4:totalDate1=90+day1;break;
case 5:totalDate1=120+day1;break;
case 6:totalDate1=151+day1;break;
case 7:totalDate1=181+day1;break;
case 8:totalDate1=212+day1;break;
case 9:totalDate1=243+day1;break;
case 10:totalDate1=273+day1;break;
case 11:totalDate1=304+day1;break;
case 12:totalDate1=334+day1;break;
}
switch(month2){
case 1:totalDate2=day2;break;
case 2:totalDate2=31+day2;break;
case 3:totalDate2=59+day2;break;
case 4:totalDate2=90+day2;break;
case 5:totalDate2=120+day2;break;
case 6:totalDate2=151+day2;break;
case 7:totalDate2=181+day2;break;
case 8:totalDate2=212+day2;break;
case 9:totalDate2=243+day2;break;
case 10:totalDate2=273+day2;break;
case 11:totalDate2=304+day2;break;
case 12:totalDate2=334+day2;break;
}
if(year1%4==0&&year1%100!=0||year1%400==0){ //判断是否是闰年
if(month1>2){
totalDate1++;
}
}
if(year2%4==0&&year2%100!=0||year2%400==0){
if(month2>2){
totalDate2++;
}
}
if(year1==year2){
midDay=totalDate2-totalDate1; //同一年就用这年的第几天天数互减
}
else{
midDay=365-totalDate1+totalDate2+(year2-year1-1)*365;//先每年定为365统计相识的天数
int i;
for(i=year1;i<year2;i++){
if(i%4==0&&i%100!=0||i%400==0){
midDay++; //然后判断是否存在闰年 有了就再加一天
}
}
}
printf("我们相识%d天
", midDay);
}