Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #define eps 0.00001
- using namespace std;
- double f(double x){
- return x*x*x-3;
- }
- double Root(double a, double b, double (*f)(double)){
- double x=(a+b)/2;
- if (fabs(f(x))<eps)
- return x;
- else{
- if (f(x)*f(a)<0)
- return Root(a,x,f);
- else
- return Root(x,b,f);
- }
- }
- int main(int argc, char *argv[])
- {
- double x = Root(0, 2, f);
- cout << x << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment