x^5+3x-1=0 (C语言源码):
/* Begin */
#include
#include
#define EXPR pow(x,5)+3*x-1
float Solve(float a,float b,float Err)
{
float x = a;
float f1,f2;
while((b - a) > Err)
{
f1 = EXPR;
x = (a + b) / 2;
f2 = EXPR;
if(f1 * f2 < 0)
{
b = x;
x = a;
}
else
{
a = x;
}
}
return x;
}
int main()
{
float ans;
ans = Solve(0,0.5,0.000005);
printf("%f",ans);
return 0;
}
/* End */