#19371: c++ 15% 不知道錯哪裡


710517@lzsh.tc.edu.tw (林東駿)

學校 : 不指定學校
編號 : 85638
來源 : [106.105.93.39]
最後登入時間 :
2020-08-15 13:01:39
a006. 一元二次方程式 | From: [106.105.93.39] | 發表日期 : 2019-09-28 17:16

 #include <iostream>
#include <math.h>
using namespace std;
int main()
{
int a,b,c,x1,x2,z;
while (cin >>a >>b >>c){
z=sqrt((b*b)-(4*a*c));
if (z>0){
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
if (x1>x2){
cout<<"Two different roots "<<"x1="<<x1<<" , "<<"x2="<<x2<<"\n";
}
else if (x1<x2){
cout<<"Two different roots "<<"x2="<<-x2<<" , "<<"x1="<<-x1<<"\n";
}
else if (x1==x2){
cout<<"Two same roots "<<"x="<<-x1<<"\n";
}
continue;
}
if (z==0){
cout<<"Two same roots "<<"x="<<"0"<<"\n";
}
else {
cout<<"No real root"<<"\n";
}
}
cout<<endl;
}

 
ZeroJudge Forum