You are on page 1of 1

main.

cpp 08/01/17, 11:11 PM

#include<iostream>
#include<math.h>
using namespace std;
float fun(float k)
{
float p;
p=k*k-5*k+2;
return p;
}
float fun1(float a,float b)
{
float p;
p=(a*fun(b)-b*fun(a))/(fun(b)-fun(a));
return p;
}
int main()
{
float a,b,x1,x2=0,e=0.1;
int i=0;
cout<<"enter a point whose function value is -ve";
cin>>a;
cout<<"point whose function valiue is +ve";
cin>>b;
x1=fun1(a,b);
cout<<x1<<"\t";
while(e>=0.001)
{
if(fun(x1)<0)
{
x2=fun1(x1,b);
cout<<"\nx1="<<x2;

}
else if(fun(x1)>0)
{
x2=fun1(a,x1);
cout<<"\nx2="<<x2;
}
if(x2>x1)
e=x2-x1;
else
e=x1-x2;
x1=x2;
//cout<<"\nthe iteration"<< i <<"is equals to"<<x1<<endl;
i++;

}
}

Page 1 of 1

You might also like