alexx876

Untitled

Nov 7th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <iomanip>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. double f1(double c)
  9. {
  10.     double z = pow(c, 3.0) - c - 1;
  11.     return z;
  12. }
  13.  
  14. double f2(double k) {
  15.     double g = 3 * (pow(k, 2.0)) - 1;
  16.     return g;
  17.  
  18. }
  19.  
  20. int main()
  21. {
  22.     int n = 0;
  23.  
  24.     long double b = 1.5, a = -1.5, c, E = 0.001,x;
  25.  
  26.     while (b - a > E) {
  27.         n++;
  28.         c = (a + b) / 2;
  29.         if (f1(b) * f1(c) < 0)
  30.             a = c;
  31.         else
  32.             b = c;
  33.  
  34.     }
  35.  
  36.     x = (a + b) / 2;
  37.  
  38.     cout << "x=" << x << endl;
  39.     cout << "n=" << n << endl;
  40.     system("pause");
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment