改成 24天 計算 ( 好用的 time1(), time2() 副程式)
(高顯忠, sjgau4311@gmail.com, 2010-12-14 10:10)
1樓
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <sys/timeb.h>
#include <time.h>
#include "sj-01.h"
#include "sj-02.h"
// ----------------------------------------------
int main()
{
double dt;
int no, t1, sum, i;
no= 10;
while (no > 0) {
time1(&t1);
sum= 0;
for (i=1;i<=no;i++) {
sum+= i;
}
time2(t1, &dt);
printf("no= %12ld, sum= %12ld, dt= %10.3lf\n",
no, sum, dt);
no*= 2;
}
pause();
return(0);
}
// ----------------------------------------------
#if 0
no= 10, sum= 55, dt= 0.000
no= 20, sum= 210, dt= 0.000
no= 40, sum= 820, dt= 0.000
no= 80, sum= 3240, dt= 0.000
no= 160, sum= 12880, dt= 0.000
no= 320, sum= 51360, dt= 0.000
no= 640, sum= 205120, dt= 0.000
no= 1280, sum= 819840, dt= 0.000
no= 2560, sum= 3278080, dt= 0.000
no= 5120, sum= 13109760, dt= 0.000
no= 10240, sum= 52433920, dt= 0.000
no= 20480, sum= 209725440, dt= 0.000
no= 40960, sum= 838881280, dt= 0.000
no= 81920, sum= -939483136, dt= 0.000
no= 163840, sum= 536952832, dt= 0.000
no= 327680, sum= -2147319808, dt= 0.000
no= 655360, sum= 327680, dt= 0.015
no= 1310720, sum= 655360, dt= 0.000
no= 2621440, sum= 1310720, dt= 0.032
no= 5242880, sum= 2621440, dt= 0.047
no= 10485760, sum= 5242880, dt= 0.046
no= 20971520, sum= 10485760, dt= 0.094
no= 41943040, sum= 20971520, dt= 0.172
no= 83886080, sum= 41943040, dt= 0.297
no= 167772160, sum= 83886080, dt= 0.641
no= 335544320, sum= 167772160, dt= 1.421
no= 671088640, sum= 335544320, dt= 2.938
no= 1342177280, sum= 671088640, dt= 5.656
Press [Esc] for stop! other key for continue...
#endif
// ----------------------------------------------