# ，为什么显示<<这个符号总是有异常

www.MyException.Cn  网友分享于：2013-04-25  浏览：3次

//=====================================
//一元二次方程根
//=====================================
#include<iostream>
#include<math.h>
using namespace std;
//-------------------------------------
void main(){
double a,b,c;
double x1,x2;
double d=b*b-4*a*c;
double f=sqrt(d);
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
if(a==0)
{cout<<"该方程不是一元二次方程"<<"\n";
if(b==0)
cout<<"该方程不成立"<<"\n";
else
cout<<"该方程的根为x1=x2= "<< -c/b <<"\n";}
if(a!=0 )
{if(d < 0)
cout<<"该方程无解"<<"\n";
else
{ if(d==0)
cout<< " 该方程的根相等x1=x2= "<< x1=-b/(2*a) << "\n";
else
cout<<"该方程的根为: "<<"x1 = "<<x1=(-b+f)/( 2*a)<<"x2 = "<<x2=(-b-f)/(2*a); }
}
}//====================================

------解决方案--------------------
<<的优先级比=要高

cout<<"该方程的根为: "<<"x1 = "<<(-b+f)/( 2*a)<<"x2 = "<<(-b-f)/(2*a); }

cout<< " 该方程的根相等x1=x2= "<< -b/(2*a) << "\n";
------解决方案--------------------

if(d==0)
{
x1=-b/(2*a);
cout<< " 该方程的根相等x1=x2= "<<x1<<-b/(2*a)<< "\n";
}

else
{
x1=(-b+f)/( 2*a);
x2=(-b-f)/(2*a);
cout<<"该方程的根为: "<<"x1 = "<<x1<<(-b+f)/( 2*a)<<"x2 = "<<x2<<(-b-f)/(2*a);
}
------解决方案--------------------

------解决方案--------------------
double d=b*b-4*a*c;

------解决方案--------------------