You are on page 1of 2

#include<iostream.

h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
float val1(float v)
{
float a=pow(v,3);
float b=pow(v,2);
float d=pow(10,-5);
float e=pow(10,-9);
float value=a-(0.01678*b)+(1.762*d*v)-(4.17671*e);
return value;
}
float val2(float v)
{
float b=pow(v,2);
float d=pow(10,-5);
float value=(2*b)-(0.01678*2*v)+(1.762*d*);
return value;
}
void main()
{
clrscr();
float x1,x2;
int tmp=0;
while (tmp==0)
{
cout<<" enter two values to find the range"<<endl;
cin>>x1>>x2;
float a1=val1(x1);
float a2=val1(x2);
float sgn=a1*a2;
cout<<sgn;
if(sgn<0)
tmp=1;
else
tmp=0;
if(tmp==1)
cout<<"the values of x1 and x2 are "<<x1<<" and "<<x2<<endl;
}
float tmp1,tmp2;
float x3=0;
tmp1=abs(x1);
tmp2=abs(x3);
cout<<tmp1<<tmp2<<endl;
float diff=abs(tmp2-tmp1);
cout<<"the initial diff is "<<diff<<endl;
while (diff>0.005 && x3<=x2)

{
x3=x1-(val1(x1)/val2(x1));
cout<<"the interim value of x3 "<<x3<<endl;
tmp1=abs(x1);
tmp2=abs(x3);
diff=abs(tmp2-tmp1);
cout<<"the difference is "<<diff<<endl;
x1=x3;
}
cout<<endl<<"the value of x is "<<x3<<endl;
getch();
}

You might also like