求一元二次方程的跟
[cpp]#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double a,b,c,x,dlt,x1,x2;
cout<<"请输入一元二次方程的各项系数:"<<endl;
cin>>a>>b>>c;
if(a==0)
{
if(b!=0)
{
x=c/b;
cout<<"方程的解为:"<<x<<endl;
}
else
cout<<"无解"<<endl;
}else{
dlt=sqrt(b*b-4*a*c);
if(dlt<0)
cout<<"无解"<<endl;
else if(dlt==0)
{
x=-b/2*a;
cout<<"方程的解为:"<<x<<endl;
}
else
{
x1=(-b+dlt)/2*a;
x2=(-b-dlt)/2*a;
cout<<"x1="<<x1<<endl;
cout<<"x2="<<x2<<endl;
}
}
return 0;
}
补充:软件开发 , C++ ,