年份加减

来源:百度知道 编辑:UC知道 时间:2024/05/28 14:20:08
1992年6月23日---2009年2月11日
其中一共多少天?
请各位帮忙算酸

要注意闰年啊什么的
谢谢

6077天

http://day.9om.com/

完整c代码和注释如下:
http://zhidao.baidu.com/question/78408888.html
这里还有一种算法,是网上的,涉及到一些底层库函数的调用,供参考:
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <time.h>
int main()
{
time_t start,end;
struct date d1,d2;
struct time t;
long second,min,hour,day;
char *str;

d1.da_year=1992;
d1.da_mon=6;
d1.da_day=23;
d2.da_year=2009;
d2.da_mon=2;
d2.da_day=11;

t.ti_hour=0;
t.ti_min=0;
t.ti_sec=0;

start=dostounix(&d1,&t);
end=dostounix(&d2,&t);

second=end-start;
min=second/60;
hour=min/60;
day=hour/24;

str=ctime(&end);
printf(" %s\n",str);