#include<iostream>
#include<cstdlib>
#include<math.h>
using namespace std;
int main ()
{
int a,b,c,d,e; //e:判別根的性質
int x,y;
cin >>a>>b>>c;
d=(b*b)-(4*a*c);
if(d>>0) //相異實根
e=1;
else if(d==0) //重根
e=2;
else if(d<<0) //無實根
e=3;
if(e==1)
{x=((-b)+sqrt(d))/2;
y=((-b)-sqrt(d))/2;
cout<<"Two different roots x1="<<x<<" , x2="<<y<<endl;}
else if(e==2)
{x=((-b)+sqrt(d))/2;
cout<<"Two same roots x=" <<x<<endl;}
else if(e==3)
cout<<"No real root"<<endl;
return 0;
}
請問這樣錯在哪
#include
#include
#include
using namespace std;
int main ()
{
int a,b,c,d,e; //e:判別根的性質
int x,y;
cin >>a>>b>>c;
d=(b*b)-(4*a*c);
if(d>>0) //相異實根
e=1;
else if(d==0) //重根
e=2;
else if(d<<0) //無實根
e=3;
if(e==1)
{x=((-b)+sqrt(d))/2;
y=((-b)-sqrt(d))/2;
cout<<"Two different roots x1="<<x<<" , x2="<<y<<endl;}
else if(e==2)
{x=((-b)+sqrt(d))/2;
cout<<"Two same roots x=" <<x<<endl;}
else if(e==3)
cout<<"No real root"<<endl;
return 0;
}
請問這樣錯在哪
if(d>>0)改成 if(d>0)
if(d<<0)改成 if(d<0)
只有=在判斷時要兩個