fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const double eps = 0.001;
  4. int main () {
  5. double a = 1;
  6. double b = 4;
  7. double c;
  8. int N = 4;
  9. double y1, y2;
  10. double F[N];
  11. for (int i = 2; i <= N; i++)
  12. {
  13. F[0] = 1;
  14. F[1] = 1;
  15. F[i] = F[i-2] + F[i-1];
  16. }
  17. double x1;
  18. double x2;
  19. double s1 = 0;
  20. int count = 0;
  21. x1 = a + (b - a) * (F[N-2]/F[N]);
  22. x2 = a + (b - a) * (F[N-1]/F[N]);
  23. y1 = (x1-1)/(x1+1);
  24. y2 = (x2-1)/(x2+1);
  25. do {
  26. if (y1 < y2) {
  27. s1 = b;
  28. b = x2;
  29. y2 = y1;
  30. x2 = x1;
  31. x1 = a + (b - x2);
  32. y1 = (x1-1)/(x1+1);}
  33. else {
  34. s1 = a;
  35. a = x1;
  36. x1 = x2;
  37. x2 = b - (x1 - a);
  38. y1 = y2;
  39. y2 = (x2-1)/(x2+1);}
  40. count++;
  41. c = abs(x1-x2);
  42. }
  43. while (c > eps);
  44. cout << (x1 + x2)/ 2 << endl;
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 4264KB
stdin
Standard input is empty
stdout
1.6