#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 );
Run Code Online (Sandbox Code Playgroud)
我的开始和结束时间都是0.000.我不理解错误的来源.
最好还是使用time(start)和time(end)或start = clock()和end = clock()来计算经过的时间.