你测试一下:
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
#include<iostream>
#include<cmath>
void findroot(double a,double b,double c)
{
double disc = b*b - 4*a*c;
if (a==0) std::cout<<"x="<<-(c/b)<<std::endl;
else if (disc==0) std::cout<<"x1=x2="<<(-b)/(2*a)<<std::endl;
else if (disc>0)
std::cout<<"x1="<<((-b)+sqrt(disc))/(2*a)<<"\t"<<"x2="<<((-b)-sqrt(disc))/(2*a)<<std::endl;
else if (disc<0)
std::cout<<"x1="<<(-b)/(2*a)<<"+"<<sqrt(-b)/(2*a)<<"i"<<"\t"
<<"x2="<<(-b)/(2*a)<<"-"<<sqrt(-b)/(2*a)<<"i"<<std::endl;
}
int main(void)
{
double a,b,c;
std::cin>>a>>b>>c;
findroot(a,b,c);
system("pause");
return 0;
}