发布网友 发布时间:2022-11-08 08:26
共1个回答
热心网友 时间:2023-11-08 12:53
Private Function f(ByVal x As Double) As Double f = Exp(-x)End FunctionPrivate Sub Command1_Click()Dim x0 As Double, e As Double, X1 As Double, n As Long, k As Long '前三个变量类型不对x0 = 0.5: e = 0.00001: n = 18k = 1Do X1 = f(x0) '这一句应放循环里 If (Abs(X1 - x0) < e) Then Print X1 Exit Do '找到根后退出循环 ElseIf (k >= n) Then Print n & "次迭代失败" Exit Do '迭代失败后退出循环 Else k = k + 1 x0 = X1 End IfLoop '刚赋值后x1-x0等于0,不应再此判断End Sub追问要C语言