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

来源:互联网 发布:gxsec软件 编辑:程序博客网 时间:2024/05/16 04:37
#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;}