Alexandre_lsv

Untitled

Feb 22nd, 2016
310
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. #define eps 0.00001
  4. using namespace std;
  5. double f(double x){
  6.     return x*x*x-3;
  7. }
  8.  
  9. double Root(double a, double b, double (*f)(double)){
  10.     double x=(a+b)/2;
  11.     if (fabs(f(x))<eps)
  12.         return x;
  13.     else{
  14.         if (f(x)*f(a)<0)
  15.             return Root(a,x,f);
  16.         else
  17.             return Root(x,b,f);
  18.     }
  19. }
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23.     double x = Root(0, 2, f);
  24.     cout << x << endl;
  25.     return 0;
  26. }
Add Comment
Please, Sign In to add comment