a*x*x+b*x+c=0方程的解、
1.两个不同的解 b*b-4*a*c>0
2.相同的两个解 b*b-4*a*c=0
3.两个不同的共轭解 b*b-4*a*c<0
#include<stdio.h>
#include<math.h>
int main()
{
printf("请计算a*x*x+b*x+c=0的值\n");
double a = 0.0, b = 0.0, c = 0.0;
double shishu = 0.0, gonge = 0.0;
printf("请输入a,b,c的值:");
scanf("%lf %lf %lf",&a,&b,&c);
double m = 0.0, x1 = 0.0, x2 = 0.0;
m = sqrt(b*b-4*a*c);
if (m > 0)
{
x1 = (-b + m) / (a * 2);
x2 = (-b - m) / (a * 2);
printf("x1=%.4lf x2=%.4lf\n",x1,x2);
}
else if (m == 0)
{
x1 = x2 = (-b) / (2 * a);
printf("x1=x2=%.4lf\n",x2);
}
else
{
shishu = (-b) / (a * 2);
gonge = sqrt((-(b * b - 4 * a * c) )/ (2 * a));
printf("x1=%8.4lf+%8.4lfi\n",shishu,gonge);
printf("x2=%8.4lf-%8.4lfi\n", shishu, gonge);
}
return 0;
}
输出结果: