Private Sub Form_click()
For x = -100 To 100 Step 1
If 2 * x ^ 2 + 7 * x - 6 = 0 Then
Print x
End If
Next x
End Sub
由于知道结果是-3和-4,所以只简单的写了,但运行时没出现结果
For x = -100 To 100 Step 1
If 2 * x ^ 2 + 7 * x - 6 = 0 Then
Print x
End If
Next x
End Sub
由于知道结果是-3和-4,所以只简单的写了,但运行时没出现结果
Option ExplicitPrivate Sub Command1_Click()
test 2, 7, -6
End Sub
Private Sub test(a As Long, b As Long, c As Long)
Dim delta As Double
Dim v1 As Double
Dim v2 As Double
delta = b ^ 2 - 4 * a * c
If delta < 0 Then
MsgBox "无解"
Else
v1 = (-b + Sqr(delta)) / (2 * a)
v2 = (-b - Sqr(delta)) / (2 * a)
MsgBox v1 & vbTab & v2
End If
End Sub