怎样用vb求一元两次方程ax^2+bx+c=0的根?
怎样用vb求一元两次方程ax^2+bx+c=0的根?
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
Dim d As Single, x1 As Single, x2 As Single
Dim r As Single, p As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a = 0 Then
Text4.Text = "一元二次方程的系数A不能为0"
Text5.Text = "一元二次方程的系数A不能为0"
Else
d = b ^ 2 - 4 * a * c
r = -b / (2 * a)
If d = 0 Then
Text4.Text = r
Text5.Text = r
ElseIf d > 0 Then
x1 = (-b + Sqr(d)) / (2 * a)
x2 = (-b - Sqr(d)) / (2 * a)
Text4.Text = x1
Text5.Text = x2
ElseIf d < 0 Then
p = Sqr(-d) / 2 * a
Text4.Text = r & "+" & p & "i"
Text5.Text = r & "-" & p & "i"
End If
End If
End Sub
您好,请您把下面的代码解释一下,特别是这个i代表什么?谢谢。p = Sqr(-d) / 2 * aText4.Text = r & "+" & p & "i"Text5.Text = r & "-" & p & "i"