fork(2) download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double up = 19.0 + (61.0/125.0);
  7. double down = -32.0 - (2.0/3.0);
  8. double rectangle = (up - down) * 8.0;
  9.  
  10. double f(double x) {
  11. return (pow(x, 4.0)/500.0) - (pow(x, 2.0)/200.0) - 0.012;
  12. }
  13.  
  14. double g(double x) {
  15. return -(pow(x, 3.0)/30.0) + (x/20.0) + (1.0/6.0);
  16. }
  17.  
  18. double area_upper(double x, double step) {
  19. return (((up - f(x)) + (up - f(x + step))) * step) / 2.0;
  20. }
  21.  
  22. double area_lower(double x, double step) {
  23. return (((g(x) - down) + (g(x + step) - down)) * step) / 2.0;
  24. }
  25.  
  26. double area(double x, double step) {
  27. return area_upper(x, step) + area_lower(x, step);
  28. }
  29.  
  30. int main() {
  31. double current = 0, last = 0, step = 1.0;
  32.  
  33. do {
  34. last = current;
  35. step /= 10.0;
  36. current = 0;
  37.  
  38. for(double x = 2.0; x < 10.0; x += step) current += area(x, step);
  39.  
  40. current = rectangle - current;
  41. current = round(current * 1000.0) / 1000.0;
  42. //cout << current - last << endl;
  43. } while( std::fabs(current - last) >= 1e-8);
  44.  
  45. cout << current << endl;
  46. return 0;
  47. }
Success #stdin #stdout 0.03s 3096KB
stdin
Standard input is empty
stdout
117.705