#include <time.h>
time_t start,end;
time (&start);
//code here
time (&end);
double dif = difftime (end,start);
printf ("Elasped time is %.2lf seconds.", dif );
我的开始时间和结束时间都是 0.000。我不明白错误的来源。
使用 time(start) 和 time(end) 或 start=clock() 和 end=clock() 来计算经过的时间是否更好。