#include
#include
#include
int main(void)
{
float x1,x2,y1,y2,x,y,e;
x1=2.0;
x2=4.0;
y1=sin(x1)-x1+1;
y2=sin(x2)-x2+1;
e=(x1-x2)/x1;
if(e<0)
e=-e;
do
{
x=(x1+x2)/2;
y=sin(x)-x+1;
if(y*y1<0)
{
x=x2;
y=y2;
}
else
{
x=x1;
y=y1;
}
}while(e<0.00001);
printf("\n The root is %f",x);
getch();
return 0;
}
No comments:
Post a Comment