求一可求两日期差的C++程序
来源:百度知道 编辑:UC知道 时间:2024/06/04 02:37:43
#include<stdio.h>
struct date{
unsigned int year;
unsigned short month;
unsigned short day;
};
inline int isleap(unsigned int year)
{
return ((year%4==0&&year%100!=0)||(year%400==0));
}
int diffdate(struct date begin,struct date end)
{
int days;
int months,years;
int tmpyear,tmpmonth,leapyear;
short monthday[2][12]={
{31,28,31,30,31,30,31,30,31,30,31},
{31,29,31,30,31,30,31,30,31,30,31}
};
if(isleap(end.year)){
leapyear =1;
}else{
leapyear = 0;
}
years = end.year - begin.year;
months = end.month - begin.month;
days = end.day - begin.day;
tmpyear = begin.year;
while(years>0){
if(isleap(tmpyear))
days+=366;
else
days+=365;