Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Exercise 93

C Exercise 93

100 Classic C Language Examples 100 Classic C Language Examples

**Problem:** Time function example 2

**Analysis:** None.

Program source code:



//  Created by www.runoob.com on 15/11/9.

//  Copyright © 2015 Runoob Tutorial. All rights reserved.

//



#include 

#include 

#include 



int main()

{

    long i=10000000L;

    clock_t start,finish;

    double TheTimes;

    printf("做%ld次空循环需要的时间为",i);

    start=clock();

    while(i--);

    finish=clock();

    TheTimes=(double)(finish-start)/CLOCKS_PER_SEC;

    printf("%f秒。\n",TheTimes);

    return 0;

}

The above example produces the following output:



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

100 Classic C Language Examples 100 Classic C Language Examples