Aleksandr_Grigoryev

HW 16 09.12.2017

Dec 9th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. const double e = 0.000001;
  5.  
  6. double function(double x)
  7. {
  8.  
  9.     return 2 + 2 * x; // исходное уравнение f(x)=0;
  10. }
  11.  
  12. double d(double a, double b, double c)
  13. {
  14.     while (b - a > e)
  15.     {
  16.         c = (a + b) / 2;
  17.         if (function(b) * function(c) < 0)
  18.             a = c;
  19.         else
  20.             b = c;
  21.     }
  22.     return ((a + b) / 2);
  23. }
  24.     int main()
  25.     {
  26.         double a, b, c;
  27.         cin >> a >> b;
  28.         cout << d(a, b, e);
  29.  
  30.  
  31.     system("pause");
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment