用vb求斐波拉切数列前n项的和

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/08 14:38:42

用vb求斐波拉切数列前n项的和
用vb求斐波拉切数列前n项的和

用vb求斐波拉切数列前n项的和
Private Sub Command1_Click()
n = InputBox("请输入n:")
f = fact(n)
Print f
End Sub
Private Function fact(ByVal n As Integer)
If n = 1 Or n = 2 Then
fact = 1
Else
fact = fact(n - 2) + fact(n - 1)
End If
End Function

Private Sub Command1_Click()
Dim m%, sum!, t%
m = InputBox("请输入项数n")
For t = 1 To m
sum = sum + Fab(t)
Next
Print m; "项的和是:"; sum
End Sub
Private Fu...

全部展开

Private Sub Command1_Click()
Dim m%, sum!, t%
m = InputBox("请输入项数n")
For t = 1 To m
sum = sum + Fab(t)
Next
Print m; "项的和是:"; sum
End Sub
Private Function Fab(ByVal n As Integer)
If n < 3 Then
Fab = 1
Else
Fab = Fab(n - 2) + Fab(n - 1)
End If
End Function

收起