VB数组的基本操作专项
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
数组的基本操作专项
1.下列VB程序功能为:根据文本框Text1中各字符的大小关系,计算各字符升序排列的序号,并将序号保存在数组y中。如文本框内容为“2011”,程序运行后y(1)~ y(4)各元素的值分别为“4,1,2,3”。
s = Text1.Text:n = Len(s)
For i = 1 To n
y(i) = 1
Next i
For i = 1 To (1)
For j = (2) To n
If (3) Then
y(j) = y(j) + 1
Else
y(i) = y(i) + 1
End If
Next j
Next i
上述程序段3各方框处的表达式分别为()
A. (1)n (2)1 (3)Mid(s, j, 1) >= Mid(s, i, 1)
B. (1)n (2)1 (3)Mid(s, j, 1) > Mid(s, i, 1)
C. (1)n-1 (2)i+1 (3)Mid(s, j, 1) >= Mid(s, i, 1)
D. (1)n-1 (2)i+1 (3)Mid(s, j, 1) > Mid(s, i, 1)
2. 有如下VB程序段:
inS = Text1.Text
n = 0
For i = 1 To Len(inS)
m=0
c = Mid(inS, i, 1)
If c >= "a" And c <= "z" Then
m = 1
ElseIf c >= "A" And c <= "Z" Then
m = 2
ElseIf c >= "0" And c <= "9" Then
m = 3
End If
b(m) = b(m) + 1
If b(m) = 2 Then n = n + 1
Next i
已知数组b各元素初始值都为0,文本框Text1中的内容为“Welcome,2019!”,执行该程序段后,变量n的值为
A.0 B.1 C.2 D.3
3. 有如下 VB 程序段:
For i = 2 To 8
For j = 1 To 8 - i
If d(j) > d(j + 2) Then temp = d(j): d(j) = d(j + 2): d(j + 2) = temp Next j
Next i
数组元素d(1)到d(8)的值依次为“71,54,58,29,31,78,2,77”,经过该程序段
“加工”后,数组元素d(1)到d(8)的值依次为
A. 2,29,31,54,58,71,77,78
B. 2,29,31,54,58,77,71,78
C. 78,77,71,58,54,31,29,2
D. 78,71,77,58,54,31,29,2
bottom = 7
For i = 2 To bottom - 1
If i Mod 2 = 0 And a(i) = a(i - 1) + a(i + 1) Then
For j = i To bottom - 1
a(j) = a(j + 1)
Next j
bottom = bottom - 1
End If
Next i
For i = 1 To bottom
Text1.Text = Text1.Text + Str(a(i))
Next i
数组元素a(1)到a(7) 各个元素的值依次为26,94,68,42,69,27,132,运行程序后,Text1中显示的内容可能的是
A.26 42 27 132
B.26 68 42 27 132
C.26 42 69 27 132
D.26 68 42 69 27 132
9.有如下VB程序段:
For i = 1 To 6
a(i) = Int(Rnd * 10) + 1
Next i
For i = 1 To 5
If i Mod 2 = 1 And a(i) > a(i + 1) Then
t = a(i): a(i) = a(i + 1): a(i + 1) = t
Else
a(i) = a(i) + 1
End If
Next i
执行程序后,a数组各元素可能是()
A.11,11,7,9,3,9
B.6,2,8,10,5,9
C.6,9,3,7,8,12
D.3,9,0,8,2,7
10.有如下VB程序段:
b(0)=0:b(1)=0:b(2)=0:
a(0) = 0: a(1) = 1: a(2) = 3: a(3) = 2: a(4) = 1: a(5) = 2
a(6) = 2: a(7) = 3: a(8) = 2: a(9) = 1: a(10) = 2
For i = 1 To 10
a(i) = a(i) - a(i - 1)
b(a(i)) = b(a(i)) + 1
Next i
该程序段运行后,数组元素b(0)b(1)b(2)的值分别为()
A.1 5 4
B. 3 6 2
C. 3 3 4
D. 2 6 2
11. 某VB程序段如下:
Dim a (1 To 6) As Integer
a(1) = Int(Rnd*2) + 1
For i = 2 To 6
a(i) = Int(Rnd*i)*2 + 1
If a(i) < a(i-1) Then
a(i) = a(i) + a(i-1)
End If
Next i
执行该程序段后,数组元素a(1)到a(6)的值可能是( )
A.2,4,6,8,10,12
B.1,1,3,7,12,23
C.2,5,9,11,10,15
D.1,3,15,16,20,23
12.有如下VB 程序段:
For i = 1 To 5
a(i) = Int(Rnd * 10)
Next i
For i = 2 To 5
If a(i) < a(i - 1) And a(i) Mod 2 = 1 Then
a(i) = a(i) + 1
ElseIf a(i) Mod 2 = 0 And i Mod 2 = 0 Then
a(i) = a(i - 1) – 1
End If
Next i