当前位置: 代码迷 >> 综合 >> 编写一个C语言语句,要求输出这个程序需要运行的时间(用clock()做) 该怎么写?
  详细解决方案

编写一个C语言语句,要求输出这个程序需要运行的时间(用clock()做) 该怎么写?

热度:43   发布时间:2024-01-21 16:03:28.0
#include <stdio.h>
#include <time.h>
int main(void)
{int i=123456789;clock_t start, end;start = clock();while(i--);end = clock();printf("The time was: %d\n", (end - start));//单位是毫秒,注意是%d,不再是%f printf("The time was: %f\n", (double)(end - start) / CLK_TCK); //单位是秒return 0;
}