fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double f(double x)
  5. {
  6. return pow(x, 3.0);
  7. }
  8.  
  9. int main()
  10. {
  11. const double ANS = 1.0 / 4.0;
  12. double a = 0.0;
  13. int N, i;
  14. double x, r1, r2, d;
  15.  
  16. for (N=1 ; fabs(a - ANS) >= 0.001; N++ ) {
  17. d = 1.0 / (double)N;
  18. r1 = f(0.0);
  19. a = 0.0;
  20. for (i=1, x=d; i<=N; i++, x+=d) {
  21. r2 = f(x);
  22. a += ((r1 + r2) * d) / 2.0;
  23. r1 = r2;
  24. }
  25. }
  26. printf("%f\n", a);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
0.250977