#37877: 20%但不知道哪裡有錯誤,可以請各位幫忙看一下嗎


Betty314350 (Betty)

學校 : 臺中市立東山高級中學
編號 : 243543
來源 : [111.83.8.15]
最後登入時間 :
2024-01-09 15:30:19
a006. 一元二次方程式 | From: [220.138.45.102] | 發表日期 : 2023-10-15 18:12

#include <iostream>
#include <math.h>
using namespace std;
 
int main() {
int a, b, c;
int d=sqrt(b*b-4*a*c);
int x1=(-1*b+d)/( 2*a);
int x2=(-1*b-d)/( 2*a);
 
cin>>a>> b>> c;
if (d==0)
cout<<"Two same roots x= "<<x1<<endl;
 
else if(d>0)
cout<<" Two different roots x1= "<<x1 <<" x2="<<x2<<endl;
 
else
cout<<"No real root"<<endl;
return 0;
}
 
 
#37879: Re: 20%但不知道哪裡有錯誤,可以請各位幫忙看一下嗎


predator (david)

學校 : 不指定學校
編號 : 239167
來源 : [1.168.11.11]
最後登入時間 :
2024-03-15 13:25:01
a006. 一元二次方程式 | From: [122.117.95.179] | 發表日期 : 2023-10-15 19:01

#include
#include
using namespace std;
 
int main() {
int a, b, c;
int d=sqrt(b*b-4*a*c);
int x1=(-1*b+d)/( 2*a);
int x2=(-1*b-d)/( 2*a);
 
cin>>a>> b>> c;
if (d==0)
cout<<"Two same roots x= "<
 
else if(d>0)
cout<<" Two different roots x1= "<
return 0;
}
 

cin>>a>> b>> c; 放錯地方了吧。

 
#37880: Re: 20%但不知道哪裡有錯誤,可以請各位幫忙看一下嗎


predator (david)

學校 : 不指定學校
編號 : 239167
來源 : [1.168.11.11]
最後登入時間 :
2024-03-15 13:25:01
a006. 一元二次方程式 | From: [122.117.95.179] | 發表日期 : 2023-10-15 19:16

我是用 visual studio 練習 cpp

你這寫法,會提示錯誤。

 
#37882: Re: 20%但不知道哪裡有錯誤,可以請各位幫忙看一下嗎


Betty314350 (Betty)

學校 : 臺中市立東山高級中學
編號 : 243543
來源 : [111.83.8.15]
最後登入時間 :
2024-01-09 15:30:19
a006. 一元二次方程式 | From: [42.76.65.188] | 發表日期 : 2023-10-15 21:09

#include
#include
using namespace std;
 
int main() {
int a, b, c;
int d=sqrt(b*b-4*a*c);
int x1=(-1*b+d)/( 2*a);
int x2=(-1*b-d)/( 2*a);
 
cin>>a>> b>> c;
if (d==0)
cout<<"Two same roots x= "<
 
else if(d>0)
cout<<" Two different roots x1= "<
return 0;
}
 

cin>>a>> b>> c; 放錯地方了吧。

太謝謝你了,我後來把它放在int a, b, c;下面,就有通過了,但還是不太了解這兩個位置的差別在哪

 
#37883: Re: 20%但不知道哪裡有錯誤,可以請各位幫忙看一下嗎


Betty314350 (Betty)

學校 : 臺中市立東山高級中學
編號 : 243543
來源 : [111.83.8.15]
最後登入時間 :
2024-01-09 15:30:19
a006. 一元二次方程式 | From: [42.76.65.188] | 發表日期 : 2023-10-15 21:26

我是用 visual studio 練習 cpp

你這寫法,會提示錯誤。


是語法錯誤嗎,但我用dev c++測試,是正確的

 
#37989: Re: 20%但不知道哪裡有錯誤,可以請各位幫忙看一下嗎


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a006. 一元二次方程式 | From: [101.137.44.123] | 發表日期 : 2023-10-22 09:19

#include
#include
using namespace std;
 
int main() {
int a, b, c;
int d=sqrt(b*b-4*a*c);
int x1=(-1*b+d)/( 2*a);
int x2=(-1*b-d)/( 2*a);
 
cin>>a>> b>> c;
if (d==0)
cout<<"Two same roots x= "<
 
else if(d>0)
cout<<" Two different roots x1= "<
return 0;
}
 

cin>>a>> b>> c; 放錯地方了吧。

太謝謝你了,我後來把它放在int a, b, c;下面,就有通過了,但還是不太了解這兩個位置的差別在哪


你還沒用cin輸入a,b,c的值,就拿來計算d,x1,x2,當然會出錯啊,你可以試試,cin之前a,b,c是多少就知道了

 
ZeroJudge Forum