单击窗体,在窗体上打印数列:2/1 ,3/2 ,5/3 ,8/5 ,13/8 … 的前10项,并求其和,将和保存在变量s中。
Private Sub Form_Click()
Dim i%, j%, k%, m As Integer
Dim s As Single
s = 0
i = 2 'i为分子
j = 1 'j为分母
For k = 1 To 10
s = 【1】
Print i & "/" & j
m = j
j = i
i = 【2】
Next
Print s
End Sub
Private Sub Form_Click()
Dim i%, j%, k%, m As Integer
Dim s As Single
s = 0
i = 2 'i为分子
j = 1 'j为分母
For k = 1 To 10
s = 【1】
Print i & "/" & j
m = j
j = i
i = 【2】
Next
Print s
End Sub
举一反三
- 下列程序: Option Base 1 Private Sub Form_Click() Dim a(5,5) For i = 1 To 5 For j = 1 To 5 k = k + 1 a (i,j)= k Next j Next i For i = 1 To 5 s = s + a (i,i) Next i Print s End Sub 运行时的输出结果是( )。
- 下列程序中 s = s + j 语句共执行了______次。 Dim s As Integer Dim i As Integer, j As Integer For i = 1 To 10 Step 2 For j = 1 To 5 Step 2 s = s + j Next j Next i Print s
- 运行下列程序,单击窗体显示的结果为( )。 Private Sub Form_Click() Dim a Dim s As Integer, i As Integer a = Array(1, 2, 3) For i = 2 To 0 Step -1 s = s + a(i) * a(i) Next i Print s End Sub
- 以下VBA程序运行的结果是( ) Public Sub Form_Click() Dim s As Integer s = 0 For i = 1 To 2 s = 1 For j = i To 3 s = s + i * j Next j Next i MsgBox "s=" &; s End Sub A: 11 B: 18 C: 22 D: 7
- 运行以下程序,单击命令按钮后在窗体上输出内容_________。Private Sub Command1_Click()Dim a() As IntegerDim i As Integer, j As IntegerReDim a(3, 4)For i = 1 To 3For j = 1 To 4a(i, j) = i* 10 + jNext jNext iReDim a(4, 5)Print a(2, 3)End Sub