vb编程 在窗体上打印数列2/1,3/2,5/3,8/5,13/8…的前10项,并求其和.
问题描述:
vb编程 在窗体上打印数列2/1,3/2,5/3,8/5,13/8…的前10项,并求其和.
答
Private Sub Form_Click()
Dim T(10) As Integer
Dim R(10) As Integer
R(0) = 1
T(0) = 2
S = 0
For i = 1 To 10
If i = 1 Then
R(i) = R(i - 1) + 1
Else
R(i) = R(i - 1) + R(i - 2)
End If
T(i) = R(i - 1) + T(i - 1)
Next i
For i = 0 To 10
S = T(i) / R(i) + S
Print T(i) & "/" & R(i)
Next i
Print "总和为:"; S
End Sub