[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;
}