Private Function qiujie(a As Double, b As Double, cha As Double) As Double
Dim c As Double
Dim y As Double
If a > b Then
c = a
a = b
b = c
End If
If fangcheng(a) * fangcheng(b) < 0 Then
c = (a + b) / 2
y = fangcheng(c)
If (y - 0) * (0 - y) * (-1) < cha Then
qiujie = y
ElseIf y > 0 Then
qiujie = qiujie(a, y, cha)
ElseIf y < 0 Then
qiujie = qiujie(y, b, cha)
Else
MsgBox "err1"
End
End If
ElseIf fangcheng(a) < 0 Then
qiujie = qiujie(a, b + 10, cha)
ElseIf fangcheng(a) > 0 Then
qiujie = qiujie(a - 10, b, cha)
Else
MsgBox "error"
End
End If
End Function
Private Function fangcheng(p As Double) As Double
fangcheng = p * p + 4 * p + 40
End Function
----------------------------------
这是递归方式实现,可以改成循环,效率 高