A. c語言:倒計時器
#include "time.h"
void main(){
int n,m,settime=10;
n=time(0);
printf("請輸入倒計時時間(秒)");
scanf("%d",&settime);
while (settime!=0){
if (n!=time(0)){//如果時間過了1秒
settime--;//計時器減1
printf("%d\n",settime);//輸入目前的倒計時
n=time(0);//更新當前時間
}
}
}
B. c語言 倒計時時鍾程序
如果你有TC,可以試一試。
VC 的 kbhit() 不能返回 鍵名。
23:59:59 -- 86400 秒
#include <stdio.h>
#include <windows.h>
#include <conio.h>
void main()
{
long int t;
int flag =0;
t = 86400;
printf("press S start, press E stop\n");
while(1)
{
if (kbhit() == 'S' || kbhit() == 's') flag =1;
if (kbhit() == 'E' || kbhit() == 'e') flag =0;
Sleep(1000);
if (flag == 1) t = t -1;
if (t <= 0) break;
printf("%d ",t);
}
C. 這么用C語言做倒計時器
tdio.h>
#include <conio.h>
#include <windows.h>
#include <stdlib.h>
struct tm //定義時間結構體,包括時分秒和10毫秒
{
int hours,minutes,seconds;
int hscd;
}time,tmp,total; //time用以計時顯示,tmp用以存儲上一階段時間,total記總時間
int cnt;
FILE* fout;
//每次調用update函數,相當於時間過了10ms
void update(struct tm *t)
{
(*t).hscd++; //10ms單位時間加1
cnt++;
if ((*t).hscd==100) //計時滿1s,進位
{
(*t).hscd=0;
(*t).seconds++;
}
if ((*t).seconds==60) //計時滿一分,進位
{
(*t).seconds=0;
(*t).minutes++;
}
if ((*t).minutes==60) //計時滿一小時,進位
{
(*t).minutes=0;
(*t).hours++;
}
if((*t).hours==24) (*t).hours=0;
//delay();
Sleep(10); //Sleep是windows提供的函數,作用是暫停程序,單位毫秒,所以此處暫停10ms
}
void display(struct tm *t)
{
//此處輸出計時結果,\r為回車不換行,既一直在同一行更新時間
printf("%d:",(*t).hours);
printf("%d:",(*t).minutes);
printf("%d:",(*t).seconds);
printf("%d\r",(*t).hscd);
//printf("Now, press 『e』 key to stop the clock…");
}
void time_init() //初始化時間
{
time.hours=time.minutes=time.seconds=time.hscd=0;
}
void get_total() //計算總時間
{
total.hscd = cnt % 100;
cnt /= 100;
total.seconds = cnt % 60;
cnt /= 60;
total.minutes = cnt % 60;
cnt /= 60;
total.hours = cnt;
}
int main()
{
char m;
time_init();
cnt = 0;
fout = fopen("timeout.txt","w");
printf("按回車鍵開始計時!\n");
while(1)
{
m = getch();
if(m != 『\r』) //讀入一個輸入,如果是回車,那麼跳出次循環
printf("輸入錯誤,僅能輸入回車鍵!\n");
else
break;
}
printf("已經開始計時,但是你可以按回車鍵以分段計時!\n");
while(1)
{
if(kbhit()) //此處檢查是否有鍵盤輸入
{
m=getch();
if(m == 『\r』) //如果等於回車,那麼計時結束,跳出循環
break;
else if(m == 『 『) //如果等於空格,顯示此次計時,初始化計時器
{
tmp = time; //記錄上一段計時器結果
fprintf(fout,"%d:%d:%d:%d\n",tmp.hours,tmp.minutes,tmp.seconds,tmp.hscd); //寫入文件
time_init();
printf("\n");
}
else
{
printf("輸入錯誤,僅支持輸入回車鍵或者空格鍵!\n");
}
}
update(&time); //更新計時器
display(&time); //顯示計時器時間
}
tmp = time; //輸出最後一次即使結果,寫入文件
fprintf(fout,"%d:%d:%d:%d\n",tmp.hours,tmp.minutes,tmp.seconds,tmp.hscd);
get_total(); //計算總的時間,顯示,並寫入文件
printf("\n總時間:%d:%d:%d:%d\n",total.hours,total.minutes,total.seconds,total.hscd);
fprintf(fout,"統計時間:%d:%d:%d:%d\n",total.hours,total.minutes,total.seconds,total.hscd);
fclose(fout);
printf("已經保存到當前目錄下的timeout.txt文件中按任意鍵結束!");
getch();
}
另外,站長團上有產品團購,便宜有保證
D. c語言倒計時程序設計:要求從鍵盤輸入倒計的時間分數和秒數,按「回車鍵」開始倒計,直到計時時間結束。
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
intmain()
{
intsec;
intmin;
printf("請輸入時間:分鍾和秒數 ");
scanf("%d%d",&min,&sec);
printf("按回車鍵開機計時 ");
getchar();
for(min;min>0;min--)
{
for(sec;sec>=0;sec--)
{
Sleep(1);
if(sec==0)
{
sec==60;
break;
}
}
}
printf("計時結束 ");
}
E. c語言倒數計時器
for (int i = 30; i >0 ; i--)
{
printf("%d\n", i);
sleep(1);
}
函數名: sleep
功 能: 執行掛起一段時間
用 法: unsigned sleep(unsigned seconds);
在VC中使用帶上頭文件
#include <windows.h>
在gcc編譯器中,使用的頭文件因gcc版本的不同而不同
#include <unistd.h>
F. 怎麼樣用c語言寫一個倒計時程序
工程名稱:99秒倒計時 //功能描述:程序開始顯示99秒等待開始倒計時,當再次按下開關後計時 //停止,當再按下開關後計時 //復位實際上是單片機復位,重新開始! //通過本程序新的認識: 1.BCD數碼管的使用 2.十進制到BCD碼轉化
G. c語言倒計時怎麼編
對硬體的啊。
p2=0;
p1=display_code[display_data[i]];
p2=k;
k=k>>1;
不懂。
不過感覺問題不大。先把main里的i的上限從250改到216.
在display()里做3個判斷(可能會要做個全局變數,或者加個參數,記錄當前是多少。)
判斷是否是0,大於10,大於100
另外,站長團上有產品團購,便宜有保證
H. c語言倒計時器 的編程代碼
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
void main(){
int t,m,s;
printf("input counterdown time in seconds\n");
scanf("%d",&t);
printf("\n===================\n");
while(1)
{
wait ( 1 );
t--;
if (t==0) break;
s = t % 60;
m = t / 60;
printf("\r\t%02d:%02d",m,s);
}
exit(0);
};
I. c語言 製作 倒計時
#include"stdio.h"
#include"Windows.h"
intmain(){
printf("請輸入倒計時時間(例如:01:26:30):");
inthour=0,min=0,sec=0;
scanf("%d:%d:%d",&hour,&min,&sec);
if(hour>24||hour<0||min>60||min<0||sec>60||sec<0){
printf("輸入有誤! ");
return0;
}
printf("倒計時開始! ");
inti,j,k;
for(i=hour;i>=0;i--){
for(j=min;j>=0;j--){
for(k=sec;k>=0;k--){
printf(" %2d:%2d:%2d",i,j,k);
Sleep(1000);
}
sec=59;
}
min=59;
}
exit(0);
}