main()
{
float a,b,c;
float temp;//计算b*b-4*a*c
float num;//开根号
float x1,x2;//方程的根
printf("Enter a,b,c:");
scanf("%f %f %f",a,b,c);
temp=b*b-4*a*c;
num=sqrt(temp);
if(temp>0) //两个不同实根
{
x1=(-b+num)/(2*a);
x2=(-b-num)/(2*a);
printf("x1=%0.2f, x2=%0.2f\n",x1,x2);//保留两位输出
}
if(temp==0)//一个相同实根
{
x1=x2=(-b)/(2*a);
printf("x1=x2=%0.2f\n",x1);//保留两位输出
}
if(temp<0)//共轭复数,无实根
{
float n;
float m;
n=sqrt(-temp);
m=2*a;
printf("x1=-%0.2f+(%0.2fi)/%0.2f%s\n",b,n,m);
printf("x1=-%0.2f-(%0.2fi)/%0.2f%s\n",b,n,m);//保留两位输出
}
}
//如输入1 1 1即x^2+x+1=0
//结果:x1=-1.00+(1.73i)/2.00
x2=-1.00-(1.73i)/2.00
//我在别处回答的供你参考