vb第四章数组习题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第一章数组
一、选择题
1.在窗体上画一个命令按钮,然后编写如下程序:
Option Base 1
Private Sub Command1_Click(Index As Integer)
Dim Arr1(12) As Integer, Arr2(3) As Integer
Dim Sum As Integer
Sum = 2
For i = 1 To 12
Arr1(i) = i
Next i
For i = 1 To 3
Arr2(i) = Arr1(i * i)
Next i
For i = 1 To 3
Sum = Sum + Arr2(i)
Next i
Print Sum
End Sub
程序运行后,单击命令按钮,在窗体上的输出结果是
A.16B.24 C.32 D.36 2.在窗体上画一个文本框,然后编写如下代码:
Option Base 1
Private Sub Form_Click()
Dim arr
Dim Start As Integer, Finish As Integer
Dim Sum As Integer
arr = Array(12, 4, 8, 16)
Start = LBound(arr)
Finish = UBound(arr)
Sum = 0
For i = Start To Finish
Sum = Sum + arr(i)
Next i
c = Sum / Finish
= c
End Sub
程序运行后,单击窗体,则在文本框中显示的内容是
A.40 B.10C.12 D.16 3.阅读程序:
Option Base 1
Private Sub Form_Click()
Dim Arr(4, 4) As Integer
For i = 1 To 4
For j = 1 To 4
Arr(i, j) = (i - 1) * 2 + j
Next j
Next i
For i = 3 To 4
For j = 3 To 4
Print Arr(j, i);
Next j
Next i
End Sub
程序运行后,单击窗体,输出结果是
A.5 7 B.6 8 C.7 9D.8 10
6 8
7 9
8 108 11 4.用下面的语句所定义的数组的元素个数是
Dim A(-3 To 5) As Integer
A.6 B.7 C.8 D.9 5.用下面的语句所定义的数组的元素个数是
Dim arr(3 To 5, -2 To 2)
A.20 B.12 C.15D.24
6.在窗体上画一个命令按钮(其Name属性为Command1),然后编写如下代码:
Private Sub Command1_Click()
Dim Arr1(10), Arr2(10) As Integer
n = 3
For i = 1 To 5
Arr1(i) = i
Arr2(n) = 2 * n + i
Next i
Print Arr2(n); Arr1(n)
End Sub
程序运行后,单击命令按钮,输出结果是
A.11 3B.3 11 C.13 3 D.3 13 7.在窗体上画一个命令按钮(其Name属性为Command1),然后编写如下代码:
Option Base 1
Private Sub Command1_Click()
Dim a(10), p(3) As Integer
k = 5
For i = 1 To 10
a(i) = i
Next i
For i = 1 To 3
p(i) = a(i * i)
Next i
For i = 1 To 3
k = k + p(i) * 2
Next i
Print k
End Sub
程序运行后,单击命令按钮,输出结果是
A.35 B.28 C.33D.37
8.在窗体上画一个命令按钮(其Name属性为Command1),然后编写如下代码:
Option Base 1
Private Sub Command1_Click()
Dim a
a = Array(1, 2, 3, 4)
j = 1
For i = 4 To 1 Step -1
s = s + a(i) * j
j = j * 10
Next i
Print s
End Sub
程序运行后,单击命令按钮,输出结果是
A.4321 B.12 C.34 D.1234 9.在窗体上画一个命令按钮(其Name属性为Command1),然后编写如下代码:
Option Base 1
Private Sub Command1_Click()
Dim Arr(3) As Integer
For i = 1 To 3
For j = 1 To 3
Arr(j) = Arr(i) + 1
Next j
Next i
Print Arr(3)
End Sub
程序运行后,单击命令按钮,输出结果是
A.7 B.6 C.5D.4 10.在窗体上画一个名称为List1的列表框,一个名称为Label1的标签框。列表框中显示若干城市的名称,当单击列表框中的某一城市名时,在标签中显示选中城市的名称。下列能正确实现上述功能的程序是