早教吧作业答案频道 -->数学-->
vb程序改错 求解一元二次方程(ax^2+bx+c=0)的程序求解一元二次方程(ax^2+bx+c=0)的程序Private Sub Command1_Click()Dim a As Integer,b As Integer,c As Integer,d As IntegerDim x1 As Single,x2 As SingleInputBox ("a=")InputBox
题目详情
vb程序改错 求解一元二次方程(ax^2+bx+c=0)的程序
求解一元二次方程(ax^2+bx+c=0)的程序
Private Sub Command1_Click()
Dim a As Integer,b As Integer,c As Integer,d As Integer
Dim x1 As Single,x2 As Single
InputBox ("a=")
InputBox ("b=")
InputBox ("c=")
d = Sqr(b * b - 4 * a * c)
x1 = (-b + d) / (2 * a)
x1 = (-b - d) / (2 * a)
Print "x1="; x1,"x2="; x2
End Sub
请问错在哪里
求解一元二次方程(ax^2+bx+c=0)的程序
Private Sub Command1_Click()
Dim a As Integer,b As Integer,c As Integer,d As Integer
Dim x1 As Single,x2 As Single
InputBox ("a=")
InputBox ("b=")
InputBox ("c=")
d = Sqr(b * b - 4 * a * c)
x1 = (-b + d) / (2 * a)
x1 = (-b - d) / (2 * a)
Print "x1="; x1,"x2="; x2
End Sub
请问错在哪里
▼优质解答
答案和解析
两处错误,第一个,没有赋值过程 ,应该改为:
a=InputBox ("a=")
b=InputBox ("b=")
c=InputBox ("c=")
第二个:x1 = (-b - d) / (2 * a)应该是
x2 = (-b - d) / (2 * a)
另外d有开方过程 ,最好设为 double而不是 integer
最好再加个判断判别式的过程:
Private Sub Command1_Click()
Dim a As Integer,b As Integer,c As Integer,d As Double
Dim x1 As Single,x2 As Single
a = InputBox("a=")
b = InputBox("b=")
c = InputBox("c=")
d = b * b - 4 * a * c
If d < 0 Then
MsgBox "判别式小于0"
Exit Sub
End If
d = Sqr(d)
x1 = (-b + d) / (2 * a)
x2 = (-b - d) / (2 * a)
Print "x1="; x1,"x2="; x2
End Sub
a=InputBox ("a=")
b=InputBox ("b=")
c=InputBox ("c=")
第二个:x1 = (-b - d) / (2 * a)应该是
x2 = (-b - d) / (2 * a)
另外d有开方过程 ,最好设为 double而不是 integer
最好再加个判断判别式的过程:
Private Sub Command1_Click()
Dim a As Integer,b As Integer,c As Integer,d As Double
Dim x1 As Single,x2 As Single
a = InputBox("a=")
b = InputBox("b=")
c = InputBox("c=")
d = b * b - 4 * a * c
If d < 0 Then
MsgBox "判别式小于0"
Exit Sub
End If
d = Sqr(d)
x1 = (-b + d) / (2 * a)
x2 = (-b - d) / (2 * a)
Print "x1="; x1,"x2="; x2
End Sub
看了 vb程序改错 求解一元二次方...的网友还看了以下:
as the result, as a result ,as a result of ,as re 2020-04-06 …
as a result of的用法As a result of keeping study,my 2020-04-06 …
Our neibour has ________oursA.as a big house as B 2020-05-13 …
with the teacher's help 的同义词组.A horse is as stron 2020-05-16 …
Yesterday my sister bought ____ the one your sist 2020-05-16 …
This is ( )as the one you bought yesterdayA.such 2020-05-16 …
——How do you like this book?——It is______ as you 2020-05-16 …
It has more than 60 specialized subject libraries 2020-05-16 …
Our neighbor has__ours A.as a big house as BOur n 2020-05-16 …
英语翻译similie as proud as peacock.as poor as a chur 2020-05-16 …