fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <time.h>
  4.  
  5. int main() {
  6. const int n = 100000;
  7. const double b = 1.0;
  8. const double a = 0.70710678118;
  9. const double h = (b - a) / n;
  10. double sqrx, x, s;
  11.  
  12. clock_t start, end;
  13. double total_time = 0.0;
  14.  
  15. for (int j = 0; j < 1000; j++) {
  16. s = 0.0;
  17. start = clock();
  18.  
  19. for (int i = 1; i < n; i ++) {
  20. x = a + h * i;
  21. sqrx = x * x;
  22. s += sqrt(1 - sqrx) / sqrx;
  23. }
  24.  
  25. end = clock();
  26. total_time += (double)(end - start) / CLOCKS_PER_SEC;
  27. }
  28.  
  29. printf("Average time: %lf seconds\n", total_time / 1000.0);
  30.  
  31. printf("s = %f", s * h);
  32. }
Success #stdin #stdout 1.08s 5288KB
stdin
Standard input is empty
stdout
Average time: 0.001079 seconds
s = 0.214600