高考结束之后,我闲来无事写了个倒计时程序,因为用来倒计时成绩发布时间,所以只提供了秒数的倒计时。
今天将它进行了一些小的修改,使其能显示天数。
源码如下:
#include <stdio.h>
#include <windows.h>
#include <time.h>
int main()
{
int year,mon,day,hour,min,sec,secs,days;
printf("year=");//年
scanf("%d",&year);
printf("
");
printf("mon=");//月
scanf("%d",&mon);
printf("
");
printf("day=");//日
scanf("%d",&day);
printf("
");
printf("hour=");//时
scanf("%d",&hour);
printf("
");
printf("min=");//分
scanf("%d",&min);
printf("
");
printf("sec=");//秒
scanf("%d",&sec);
printf("
");
struct tm fixDate;
fixDate.tm_year = year-1900;
fixDate.tm_mon = mon-1;
fixDate.tm_mday = day;
fixDate.tm_hour = hour;
fixDate.tm_min = min;
fixDate.tm_sec = sec;
time_t lt;
time_t fixTime_t = mktime(&fixDate);
while(1)
{
system("cls");
lt =time(NULL);
printf("剩余 %d 秒
",fixTime_t-lt);
secs=fixTime_t-lt;
days=secs/86400+1;//一小时3600秒,一天24小时=86400秒,因为相除取整,所以要加1
printf("剩余%d天
",days);
Sleep(980);
}
return 0;
}