Вы находитесь на странице: 1из 1

#include<stdio.

h>
#include<conio.h>
#include<math.h>
main()
{
float x0,x1,x2,fx,fx0,fx1,fx2,tol,abs;
x0=0; x1=1; tol=0.0001;
fx0=pow(x0,3)+2*(sin(x0))-7;
fx1=pow(x1,3)+2*(sin(x1))-7;
if(fx0*fx1<0)
{
x2=(x0+x1)/2;
fx2=pow(x2,3)+2*(sin(x2))-7;
}
else()
{
printf("The root is not between x1 and x2.");
getch();
}
if(fx2<0)
abs=fx2*(-1);
else()
abs=fx2;
//table
printf("ITER.\tx0\tx1\tx2\tf(x0)\tf(x2)\tf(x0)*f(x2)\t|f(x2)|\tREMARKS")
//repeat
while(abs>tol)
{
x2=(x0+x1)/2;
fx2=pow(x2,3)+2*(sin(x2))-7;
fx0=pow(x0,3)+2*(sin(x0))-7;
if(fx0*fx2<0)
x1=x2;
else()
x0=x2;
if(fx2<0)
abs=fx2*(-1);
if(fx2>0)
abs=fx2;
if(abs<tol)
printf("The root is %.4f",x2);
}
}