當前位置:首頁 » 編程語言 » 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);
}

熱點內容
易語言殺毒源碼 發布:2025-05-02 07:14:22 瀏覽:510
win10配置java 發布:2025-05-02 07:05:40 瀏覽:725
如何ftp伺服器傳文件 發布:2025-05-02 06:59:28 瀏覽:827
安卓照片怎麼搞放大鏡 發布:2025-05-02 06:54:31 瀏覽:349
老王壓縮包 發布:2025-05-02 06:42:18 瀏覽:193
sql資料庫怎麼打開文件 發布:2025-05-02 06:41:36 瀏覽:876
阿里雲伺服器和華為雲哪個好 發布:2025-05-02 06:40:59 瀏覽:338
協作源碼 發布:2025-05-02 06:36:00 瀏覽:210
安裝python2 發布:2025-05-02 06:30:53 瀏覽:751
谷歌安卓輸入法如何輸入中文 發布:2025-05-02 06:30:44 瀏覽:960