该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include"stdio.h"
main()
{
int y1,y2,m1,m2,d1,d2,days,i,t,day1,day2,day3;
printf("输入起始日期(xxxx-xx-xx): ");
scanf("%d-%d-%d",&y1,&m1,&d1);
printf("输入截止日期(xxxx-xx-xx): ");
scanf("%d-%d-%d",&y2,&m2,&d2);
if(y1>y2||(y1=y2&&m1>m2)||y1==y2&&m1==m2&&d1>d2)
{
t=y1;y1=y2;y2=t;
t=m1;m1=m2;m2=t;
t=d1;d1=d2;d2=t;
}
day1=0;
i=1;
while(i<=m1-1)
{
if(i==1||i==3||i==5||i==7||i==8||i==10)
day1+=31;
if(i==4||i==6||i==9||i==11)
day1+=30;
if(i=2)
day1+=28;
i++;
}
day1+=d1;
if(y1%4==0&&y1%100!=0||y1%400==0&&(m1>=3))
{
day1++;
}
day2=0;
i=1;
while(i<=m2-1)
{
if(i==1||i==3||i==5||i==7||i==8||i==10)
day2+=31;
if(i==4||i==6||i==9||i==11)
day2+=30;
if(i=2)
day2+=28;
i++;
}
if(y2%4==0&&y2%100!=0||y2%400==0&&(m2>=3))
{
day3++;
}
day3=0;
i=y1+1;
while(i<=y2-1)
{
if(i%4==0&&i%100!=0||i%400==0)
day3+=366;
else
day3+=365;
i++;
}
if(y1==y2)
days=day2-day1;
else
{
if(y1%4==0&&y1%100!=0||y1%400==0)
days=day2+day3+(366-day1+1);
else
days=day2+day3+(365-day1+1);
}
printf("之间共有%d天",days);
}