文章
11
粉丝
69
获赞
1
访问
6.6k
#include <stdio.h>
#include<stdbool.h>
bool isL(int year)//判断闰年
{
if((year%4==0&&year%100!=0)||year%400==0)
return true;
else return false;
}
int function_days(int data)//计算从公元元年到输入日期的相隔日期
{
int year,month,day;
int days=0;
int m[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
year=(data/10000);
month=((data%10000)/100);
day=(data%100);
for (int i=1;i<year;i++)
{
if( isL(i)) days+=366;
else days+=365;
}
for (int j=1;j<month;j++)
{
if(isL(year)) m[2]=29;
days+=m[j];
}
days+=day;
return days;
}
int main()
{
int data1,data2;
scanf("%d",&data1);
scanf("%d",&data2);
int ans= function_days(data2)- function_days(data1)+1;
printf("%d\n",ans);
return 0;
}
登录后发布评论
暂无评论,来抢沙发