Option Explicit
Function fact(n) As Double
Dim a(n) As Single, i%
For i = 1 To 2
a(i) = 1
Next i
For i = 3 To 20
a(i) = a(i - 1) + a(i - 2)
Next i
fact = a(i)
End Function
Private Sub Command1_Click()
Dim n As Integer, m As Double
m = fact(n)
Label1.Caption = m
End Sub
请问那里出现错误,急需解决
Function fact(n) As Double
If n > 3 Then
fact = fact(n - 2) + fact(n - 1)
Else
fact = 1
End If
End Function
Private Sub Command1_Click()
Dim n As Integer, m As Double
n = Val(Text1.Text)
If n < 0 Then
Exit Sub
End If
m = fact(n)
Label1.Caption = m
End Sub