I want to write a program in c++ to solve quadratic equation
example 2x^2+x-1=0
*hint:
ax^2+bx+c=0 becomes
x = (-b+-sqrt(b^2-4ac))/2a
1 2 3 4 5 6 7 8
|
float get_x1(float a, float b, float c)
{
return (-b + sqrt(b*b - 4 * a * c)) / (2 * a);
}
float get_x2(float a, float b, float c)
{
return (-b - sqrt(b*b - 4 * a * c)) / (2 * a);
}
|
The rest of the program is up to you.
Last edited on