#25143: 哪裡錯了? solve it 時 NA


edisonwu0102@gmail.com (吳翊睿)


#include<iostream>

#include<math.h>

using namespace std;

 

int main()

{

int a,b,c,x1,x2;

float temp;

while(cin>>a){

cin>>b;

cin>>c;

if(b*b-(4*a*c)<0){

cout<<"No real root"<<endl;

}

else if(b*b-(4*a*c)==0){

cout<<"Two same roots x="<<-b/2*a<<endl;

}

else if(b*b-(4*a*c)>0){

temp=sqrt(b*b-(4*a*c));

x1=(-b+temp)/(2*a);

x2=(-b-temp)/(2*a);

if(x1>x2){

cout<<"Two different roots x1="<<x1<<" , x2="<<x2<<endl;

}

else{

cout<<"Two different roots x1="<<x2<<" , x2="<<x1<<endl;

}

}

}

 

    return 0;

}

 

#25180: Re:哪裡錯了? solve it 時 NA


000h (000h)


cout<<"Two same roots x="<<-b/2*a<<endl;

*乘除順序應為:-b/(2*a)