當前位置:首頁 » 編程語言 » c語言倒計時教程
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言倒計時教程

發布時間: 2022-10-02 19:52:52

c語言 倒計時程序

對硬體的啊。

P2=0;
P1=display_code[display_data[i]];
P2=k;
k=k>>1;
不懂。

不過感覺問題不大。先把main里的i的上限從250改到216.
在display()里做3個判斷(可能會要做個全局變數,或者加個參數,記錄當前是多少。)
判斷是否是0,大於10,大於100
另外,站長團上有產品團購,便宜有保證

❷ 如何在c語言程序中插入一個倒計時命令

#include <stdio.h>
int main()
{
printf("hello world");
for(int i=60;i>0;i--)
{
printf("%d",i);
Sleep(1000);
}
}

❸ 怎麼用C語言實現倒數十秒鍾

你看看這個,就是完成倒計時的:
#include <stdio.h>
#include <time.h>

void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
int main ()
{
int n;
printf ("Starting countdown...\n");
for (n=10; n>0; n--)
{
printf ("%d\n",n);
wait (1);
}
printf ("FIRE!!!\n");
return 0;
}

❹ 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語言做倒計時器

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();

}
另外,站長團上有產品團購,便宜有保證

❻ 如何用c語言實現從現在到某天的倒計時

取得系統時間,用指定時間的年,月,日,時,分,秒,分別減去系統對應的位,所得時間換算成秒,然後就用秒錶的原理,每過一秒,把剩餘時間除以一年的秒數,余數再除以一個月的秒數,以此類推,然後把它輸出到屏幕。

time_t tTime; //距1900年1月1日的秒數
char str[80];
struct tm* stTm; //時間結構,格式請見其它回答
time(&timer);
stTm = localtime(&tTime);
strftime(str,sizeof(str),"%Y%m%d",stTm);//格式化時間
printf(str);//輸出

另外,格式化時間的格式說明如下,希望對你有幫助:
%a 星期幾的簡寫
%A 星期幾的全稱
%b 月分的簡寫
%B 月份的全稱
%c 標準的日期的時間串
%C 年份的後兩位數字
%d 十進製表示的每月的第幾天
%D 月/天/年
%e 在兩字元域中,十進製表示的每月的第幾天
%F 年-月-日
%g 年份的後兩位數字,使用基於周的年
%G 年分,使用基於周的年
%h 簡寫的月份名
%H 24小時制的小時
%I 12小時制的小時
%j 十進製表示的每年的第幾天
%m 十進製表示的月份
%M 十時製表示的分鍾數
%n 新行符
%p 本地的AM或PM的等價顯示
%r 12小時的時間
%R 顯示小時和分鍾:hh:mm
%S 十進制的秒數
%t 水平製表符
%T 顯示時分秒:hh:mm:ss
%u 每周的第幾天,星期一為第一天 (值從0到6,星期一為0)
%U 第年的第幾周,把星期日做為第一天(值從0到53)
%V 每年的第幾周,使用基於周的年
%w 十進製表示的星期幾(值從0到6,星期天為0)
%W 每年的第幾周,把星期一做為第一天(值從0到53)
%x 標準的日期串
%X 標準的時間串
%y 不帶世紀的十進制年份(值從0到99)
%Y 帶世紀部分的十制年份
%z,%Z 時區名稱,如果不能得到時區名稱則返回空字元。
%% 百分號

❼ 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);//更新當前時間
}
}
}

❽ 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);

}

❾ c語言倒計時怎麼編

定位要倒計時的坐標!然後再需要倒計時的地方添加gotoxy(所定位的坐標),當然這只是十以下的倒計時,超過了十則會清除不了十位數上的數字,要解決這個辦法就是輸出%2d

❿ 怎麼樣用c語言寫一個倒計時程序

工程名稱:99秒倒計時 //功能描述:程序開始顯示99秒等待開始倒計時,當再次按下開關後計時 //停止,當再按下開關後計時 //復位實際上是單片機復位,重新開始! //通過本程序新的認識: 1.BCD數碼管的使用 2.十進制到BCD碼轉化