#include <stdio.h>
#include <math.h>
/*一般式:ax²+bx²+c = 0*/
/*
1.判断 a 是否为0
2.a = 0 ,x1 = x2 = -c/b
3.a != 0,判断b²-4ac是否小于0
*/
int main()
{
float a = 0.0f;
float b = 0.0f;
float c = 0.0f;
float d = 0.0f;
float x1 = 0.0f;
float x2 = 0.0f;
float x = 0.0f;
printf("请输入a,b,c值:\n");
scanf("%f %f %f", &a, &b, &c);
if (a == 0)
{
x1 = x2 = -c/b;
}
else
{
d = b * b - 4 * a * c;
if (d >= 0)
{
x1 = -(b + sqrt(d)) / (2.0*a);
x2 = -(b - sqrt(d)) / (2.0 * a);
}
else
{
x1 = -(b + sqrt(-d)) / (2.0 * a);
x2 = -(b - sqrt(-d)) / (2.0 * a);
}
}
printf("x1=%f x2=%f", x1, x2);
return 0;
}