#include<stdio.h>
#include<math.h>
main()
{
float a, b, c, d, x1, x2, s, r;
printf("\n\n输入a, b和c。");
scanf("%f %f %f", &a, &b, &c);
d = b * b - 4 * a * c;
if (d >= 0) //▲大于或者等于0的时候直接算两个实根
{
x1 = (-b + sqrt(d)) / (2 * a);
x2 = (-b - sqrt(d)) /( 2 * a);
printf("x1=%f,x2=%f\n", x1, x2);
}
else //▲小于0的时候有两个虚根
{
r = -b / (2 * a);
s = sqrt(d) / (2 * a);
printf("x1=%f+%fi,x2=%f-%fi\n",r,s,r,s);
}
}
04-05
10-27
1343
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)