You are on page 1of 1

#include<iostream>

#include<cmath>
#define f(x) (pow(x,3)+x-11)
using namespace std;
int main()
{
float a, b, m, Error, ReqError;
int i=0;
cout<<"\t Bisection Mehtod";
cout<<"\n Enter the lower limit of an interval";
cin>>a;
cout<<"\n Enter the upper limit of an interval";
cin>>b;
cout<<"\n Required Accuracy (in %)";
cin>>ReqError;
do
{
m=(a+b)/2;
if(f(a)*f(m)<0)
{b=m;
Error=fabs(-m)*100;}
else
{a=m;
Error=fabs(m-b)*100;}
i++;
cout<<"\n Itteration"<<i<<"\t Root "<<m <<"\t Error"<<Error;
}
while(Error>ReqError);
cout<<"\n The approximative root of given equation is found to
be"<<m<<" up to " <<Error<<" fter"<<i<<" by using Bisection Method";

system("pause");
return 0;
}

You might also like