用VB设计一个求解一元二次方程Ax2+Bx+C=0的程序(A、B、C的值是任意的).
用VB设计一个求解一元二次方程Ax2+Bx+C=0的程序(A、B、C的值是任意的).
这个我直接用的4个command控件,如果你学过应该能看懂
Dim a As Integer, b As Integer, c As Integer
Private Sub Command1_Click()
a = InputBox("请输入二次项系数", "输入")
End Sub
Private Sub Command2_Click()
b = InputBox("请输入一次项系数", "输入")
End Sub
Private Sub Command3_Click()
c = InputBox("请输入常数项", "输入")
End Sub
Private Sub Command4_Click()
If b ^ 2 - 4 * a * c >= 0 Then
If b ^ 2 - 4 * a * c > 0 Then
X1 = (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
X2 = (-b - Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
MsgBox "x1=" & Format(X1, "#0.00") & vbCrLf & "x2=" & Format(X2, "#0.00")
End If
If b ^ 2 - 4 * a * c = 0 Then
X1 = (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
MsgBox "x1=" & Format(X1, "#0.00")
End If
Else
d = (-b / (2 * a))
s = Sqr(-b ^ 2 + 4 * a * c)
MsgBox "x1=" & Format(d, "#0.00") & "+" & Format(s, "#0.0") & "i" & Chr(13) & "x2=" & Format(d, "#0.00") & "-" & Format(s, "#0.0") & "i"
End If
End Sub