當前位置:編程學習大全網 - 網站源碼 - 倒計時器c語言源程序

倒計時器c語言源程序

#include <stdio.h>

#include <time.h>

struct Clock

{

int sec,min,hour;

void tick();

void show();

void run();

void set(int h,int m,int s);

};

void Clock::tick()

{

long t=time(NULL);

while(t==time(NULL));

if(--sec<0){

sec=59;

if(--min<0){

min=59;

--hour;

}

}

}

void Clock::show()

{

printf("\r");

if(hour<10)

printf("0");

printf("%d:",hour);

if(min<10)

printf("0");

printf("%d:",min);

if(sec<10)

printf("0");

printf("%d",sec);

}

void Clock::run()

{

while(sec!=0||min!=0||hour!=0){

tick();

show();

}

}

void Clock::set(int h,int m,int s)

{

hour=h;

min=m;

sec=s;

}

int main()

{

int s,m,h;

printf("請輸入時間(hhmmss):");

scanf("%d%d%d",&h,&m,&s);

Clock c;

c.set(h,m,s);

c.run();

printf("time is over!!!\a");

}

  • 上一篇:編程:手機網站怎麽下載下來html源代碼
  • 下一篇:急,手機設置裏法律信息裏有個開放源代碼許可,是什麽,我點了
  • copyright 2024編程學習大全網