你的公式写错了,还好百度了下.
Function asd(a As Double, n As Long) As Double
Dim x As Double
x = 1
For i = 1 To n 'n控制精度,数值越大精度越高,一般100以内就可以了
x = (x + (a / x)) / 2 '这里右边的 x 对应x(n),左边的 x 对应计算结果x(n+1)
Next i
asd = x
End Function
'窗体增加3个文本框以及一个按钮,Text1输入a,Text2输入精度,Text3显示结果
Private Sub Command1_Click()
Text3.Text = asd(Val(Text1.Text), Val(Text1.Text))
End Su