Current location - Training Enrollment Network - Mathematics courses - Write an algorithm statement for a math problem in senior two.
Write an algorithm statement for a math problem in senior two.
# include & ltstdio.h & gt

# include & ltmath.h & gt

Floating point function (floating point x)

{

Floating f;

f = x * x-2 * x- 1;

Return f;

}

void main()

{

float x 1,x2,x0,fx 1,fx2,fx0

x 1 = 0; x2 = 3;

FX 1 = function (x1);

Fx2 = function (x2);

do

{

x0 =(x 1+x2)/2.0;

Fx0 = function (x0);

if(fx0 * FX 1 & lt; 0)

{

x2 = x0

fx2 = fx0

}

other

{

x 1 = x0;

FX 1 = fx0;

}

}while(fabs(fx0)>= 1e-5);

Printf ("root is %f", x0);

}