當前位置:首頁 » 編程語言 » c語言程序計時

c語言程序計時

發布時間: 2025-03-02 04:17:23

① 請問c語言能不能做一個倒計時的功能

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>

void my_menu(void)
{
system("cls");

printf("界面\n");
}

void my_operate(void)
{
printf("%c\n", getch());//注意:可以將輸入值用數組等保存,這里沒有保存
}

void my_time(void)
{
int i;

for (i=60; i>0; i--)
{
Sleep(999);
system("cls");
printf("倒計時:%d\n", i);

printf("\n請輸入一個字元:");
if (kbhit())
{
my_operate();
}
}

my_menu();
}

int main(void)
{
my_time();

return 0;
}

② 關於C語言程序設計的計時器

C語言中的頭文件time.h中定義了庫函數clock(),
它返回的是從程序運行開始算起的時間,一時鍾周期為單位,
time.h還定義了符號:CLOCKS_PER_SEC,
即一秒鍾的時鍾周期。這樣就簡單了,
在頭文件中加入#include<time.h>,在程序main()主函數的開頭定義long now=0;
並給把clock()賦值給now,即now=clock();記錄程序開始時的時間,clock()會繼續增加,
但now已經確定為開始那一時刻clock()的值,
在程序結尾,算式clock()-now就是程序執行所需的時間,
但是是以時鍾周期為單位的,
如果想得到以秒為單位的時間只要輸出(clock()-now)/CLOCKS_PER_SEC就是了,
即在程序結尾添加
printf("%f",(clock()-now)/CLOCKS_PER_SEC);就可以了。

③ 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);
}

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:642
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:369
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:89
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:312
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:795
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:348
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:213
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:819
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:369
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:596