程序使用VB写的,我已经给你改好了,你试试吧.
Private Sub Command1_Click()
Dim a As Double
a = Val(Text1.Text)
Dim b As Double
b = Val(Text2.Text)
Dim c As Double
c = Val(Text3.Text)
Dim X As Double
Dim y As Double
If a = 0 Then
If b 0 Then
MsgBox "该函数不是一元二次函数,函数解为 X= " & -c / b,vbYesNo
End
Else
MsgBox "错误!无解,请检查!",vbYesNo
End
End If
Else
If (b ^ 2 - 4 * a * c) >= 0 Then
X = ((-b + Sqr(b ^ 2 - 4 * a * c))) / (2 * a)
Text4.Text = X
y = ((-b - Sqr(b ^ 2 - 4 * a * c))) / (2 * a)
Text5.Text = y
Else
X = Str(-b / (2 * a)) & "+" & Str(Sqr(4 * a * c - b ^ 2) / (2 * a)) & "i"
Text4.Text = X
y = Str(-b / (2 * a)) & "-" & Str(Sqr(4 * a * c - b ^ 2) / (2 * a)) & "i"
Text5.Text = y
End If
End If
End Su