编写一程序,求一元二次方程ax^2+bx+c=0(a<>0)的解

2025-05-23 20:41:37
推荐回答(2个)
回答1:

float fun(float x,float a,float b,float c)
{
float temp;
temp = b*b - 4*a*c;
if (a==0||temp<0)
{cout<<"ERROR"cout<return 0;
}
else return (-b+sqrt(temp))/(2*a);
}

//只返回值较大的根

回答2:

x=(-b+或-根号下b^2-4ac)/2a