帮我用c语言写一个计时器
下面是一个简单的计时器程序,使用C语言编写:
#include <stdio.h>
#include <time.h>
int main()
{
clock_t start_time, end_time;
double elapsed_time;
printf("Press enter to start the timer...\n");
getchar();
start_time = clock();
printf("Press enter to stop the timer...\n");
getchar();
end_time = clock();
elapsed_time = (double)(end_time - start_time) / CLOCKS_PER_SEC;
printf("Elapsed time: %.2f seconds\n", elapsed_time);
return 0;
}
该程序使用clock()函数来获取程序启动以来的CPU时间,然后计算经过的时间。用户按下回车键开始计时,再按下回车键停止计时。程序输出经过的时间,以秒为单位
原文地址: https://www.cveoy.top/t/topic/emEi 著作权归作者所有。请勿转载和采集!