#include"stdio.h"
#include"math.h"
void main()
{
float a,b,c,p,x1,x2,real,imag;
printf(“请输入一元二次方程的三个系数:”);
scanf("%f%f%f",&a,&b,&c);
if(a==0 &&b!=0)
printf("方程有一个根:%f\n",-c/b);
else if(a!=0)
{
p=b*b-4*a*c;
real=-b/(2*a);
imag=sqrt(fabs(p))/(2*a);
if(p==0)
printf("方程有一个根:%f\n",real);
else if(p<0)
{
printf("方程有两个共轭复根:\n");
printf("%8f+%fi\n",real,imag);
printf("%8f-%fi\n",real,imag);
}
else
{
x1=real+imag;
x2=real-imag;
printf("方程有两个实根:\n");
printf("%10f and %f\n",x1,x2);
}
}
else
printf("非法输入或无意义!\n");
}
#include"math.h"
void main()
{
float a,b,c,p,x1,x2,real,imag;
printf(“请输入一元二次方程的三个系数:”);
scanf("%f%f%f",&a,&b,&c);
if(a==0 &&b!=0)
printf("方程有一个根:%f\n",-c/b);
else if(a!=0)
{
p=b*b-4*a*c;
real=-b/(2*a);
imag=sqrt(fabs(p))/(2*a);
if(p==0)
printf("方程有一个根:%f\n",real);
else if(p<0)
{
printf("方程有两个共轭复根:\n");
printf("%8f+%fi\n",real,imag);
printf("%8f-%fi\n",real,imag);
}
else
{
x1=real+imag;
x2=real-imag;
printf("方程有两个实根:\n");
printf("%10f and %f\n",x1,x2);
}
}
else
printf("非法输入或无意义!\n");
}