/********************************************************** * File: cpi_serial.c * Purpose: Serial computation of pi in C with measurement * of the time taken to complete the computation. **********************************************************/ #include #include int main() { int n = 4800000, i, sp, ep; double pi, h, sum = 0.0, x, time; clock_t st, et; sp = 1; ep = n; st = clock(); // get the start time of the pi computation h = 1.0 / n; for(i=sp; i<=ep; i++) { x = h * (i-0.5); sum = sum + 4.0/(1.0+x*x); } pi = h * sum; et = clock(); // get the end time of the pi computation printf("pi: %.16f\n", pi); printf("execution time: %.6f sec\n", (double)(et-st)/(double)CLOCKS_PER_SEC); return 0; }