# include & ltmath.h & gt
浮點GetEquation(浮點x)
{
返回x * x-7 * x+10;
}
void main()
{
浮點a = 0;
浮點b = 6;
浮點結果= 0;
做{
float c = a+0.618 *(b-a);
float d = a+b-c;
if(fabs(get equation(c))& lt;fabs(GetEquation(d)))
{
a = d;
結果= c;
}
其他
{
b = c;
結果= d;
}
} while(fabs(get equation(result))& gt;0.01);
printf(" f(a)= a * a-7 * a+10 \ n ");
printf("a=%f\n ",結果);
}