谁会用C语言编写奥运会倒计时的程序吗?

来源:百度知道 编辑:UC知道 时间:2024/05/21 20:03:07
输入任何日期就可以看到离奥运会还有多少天

#include <stdio.h>
#include <time.h>

int main(void)
{
struct tm opm29th,input;
time_t inp,opm;
double diff;
opm29th.tm_year=2008-1900;
opm29th.tm_mday =8;
opm29th.tm_mon=7;
opm29th.tm_hour=0;
opm29th.tm_min=0;
opm29th.tm_sec=0;

printf("Year:\t");
scanf("%d",&input.tm_year);
printf("Month:\t");
scanf("%d",&input.tm_mon);
printf("Day of the month:\t");
scanf("%d",&input.tm_mday);
input.tm_year-=1900;
input.tm_mon-=1;
input.tm_hour=0;
input.tm_min=0;
input.tm_sec=0;
inp=mktime(&input);
opm=mktime(&opm29th);
diff=difftime(opm,inp);
printf("%ld Days",(long int)diff/3600/24);