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;
  14.  
  15. for (N=1 ; fabs(a - ANS) >= 0.001; N++ ) {
  16. double x;
  17. double d = 1.0 / (double)N;
  18. for (x=0.0, a=0.0; x<=1.0; x+=d)
  19. a += ((d + d) * f(x)) / 2.0;
  20. }
  21.  
  22. printf("%f\n", a);
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.03s 1720KB
stdin
Standard input is empty
stdout
0.249001