这样?
Function fun(x As Integer) As Integer
Dim a As Integer, b As Integer, c As Integer, n As Integer
a = 1
b = 1
c = 0
For n = 3 To x
c = a + b
a = b
b = c
Next
Return c
End Function
Private Sub Form_Click()
Dim n As Integer
n = InputBox("")
Print fun(n)
End Sub
Function fun(x As Integer) As Integer
a = 0
b = 1
For n = 3 To x
c = a + b
a = b
b = c
Next n
fun = c
End Function
Private Sub Form_Click()
Dim n As Integer
n = Val(InputBox(""))
Print fun(n)
End Sub
你这个是正确的!
n = 2
可以不要,放在哪里也不影响结果!