You are on page 1of 1

#include<iostream> #include<cmath> using namespace std; #define MAXITER 50 #define EPS 1.

0e-10 //define the f(x) function double f(double x){ return (x-cos(x)); } double bisect(double a,double b){ int n; double c; for(n=0;n<MAXITER;n++){ c=(a+b)/2.0; if(fabs(f(c))<EPS) break; mes close to the convergence point(root) if(f(a)*f(c)<0.0) b=c; else a=c; } return c; } int main(void){ double a,b,root; cout<<"Enter 2 starting values : "<<endl; //define the two starting points cout<<"A : "; cin>>a; cout<<"B : "; cin>>b; root = bisect(a,b); cout<<"Root is at : "<<root<<endl; return 0; } //define accuracy of convergence

//break if solution beco

You might also like