4、输入一元二次方程的三个系数,若b*b-4*a*c>0显示二个根,若=0显示一个根,反之显示无实根。
# include <iostream.h>
# include <math.h>
main()
{
float a,b,c,x1,x2,x;
cin>>a>>b>>c;
if (b*b-4*a*c>0)
{
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
}
cout<<x1<<x2;
if (b*b-4*a*c==0)
{
x=(-b+sqrt(b*b-4*a*c))/(2*a);
}
cout<<x1;
if (b*b-4*a*c<0)
cout<<"无实根";
# include <iostream.h>
# include <math.h>
main()
{
float a,b,c,x1,x2,x;
cin>>a>>b>>c;
if (b*b-4*a*c>0)
{
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
}
cout<<x1<<x2;
if (b*b-4*a*c==0)
{
x=(-b+sqrt(b*b-4*a*c))/(2*a);
}
cout<<x1;
if (b*b-4*a*c<0)
cout<<"无实根";