C 实战练习题目93

题目:时间函数举例2

程序分析:无。

程序源代码:

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4  
 5 int main()
 6 {
 7     long i=10000000L;
 8     clock_t start,finish;
 9     double TheTimes;
10     printf("做%ld次空循环需要的时间为",i);
11     start=clock();
12     while(i--);
13     finish=clock();
14     TheTimes=(double)(finish-start)/CLOCKS_PER_SEC;
15     printf("%f秒。\n",TheTimes);
16     return 0;
17 }

以上实例运行输出结果为:

做10000000次空循环需要的时间为0.025367秒。

感谢你的阅读,请用心感悟!希望可以帮到爱学习的你!!分享也是一种快乐!!!请接力。。。

点击查看原文,谢谢!

posted @ 2020-08-13 21:08  C语言自学网  阅读(120)  评论(0编辑  收藏  举报