1、VB专题 随机数逻辑判断类一、经典题组1.(2019年4月选考真题)有如下VB程序段: flag = True : i = 1 Do While i 50 Then a(i)= x flag = Not flag i = i + 1 End if Loop执行该程序段后,在下列选项中,a(1)a(6)各元素值不可能的是( )A.52,95,46,74,77,83B.50,55,46,70,21,97C.62,78,57,61,69,50D.31,54,48,72,50,822.(2018年11月选考真题)有如下VB程序段:For i=1 To 6a(i)= Int(Rnd * 10)+1Nex
2、t i For i=1 To 5If 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)+1End IfNext i执行该程序段后,a(1) a(6)各元素可能的值是( )A.11,11,7,9,3,9 B.6,2,8,10,5,9C.6,9,3,7,8,12 D.3,9,0,8,2,7二、高频考点3.(2019年9月名校协作体联考)某VB程序段如下: Dim a(1 To 6) As Integer Randomize a(1) = Int(Rnd * 2) + 1 For i = 2 To
3、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,12B. 1,1,3,7,12,23C. 2,5,9,11,10,15 D. 1,3,15,16,20,234.(2019年3月稽阳联考卷)有如下VB程序段: a(1) = 1 For i = 2 To 6 Randomize a(i) = a(i - 1) + Int(Rnd * 5 + 1) If a(i) Mod 2 = 1 Th
4、en a(i) = a(i) 2 + 1 Else a(i) = a(i) / 2 End If Next i 执行程序后,a数组各元素可能是( )A1 3 4 6 7 9 B1 2 0 3 5 6 C1 2 3 4 5 4 D1 3 4 5 1 15.(2019年4月柯桥区方向性试卷)有如下VB 程序段:For i = 1 To 6a(i) = Int(Rnd() * 10) + 1If a(i) Mod 2 i Mod 2 Then i = i - 1Next iFor i = 1 To 5For j = 6 To i + 2 Step -1If a(j) a(j - 2) Thent =
5、 a(j): a(j) = a(j - 2): a(j - 2) = tEnd IfNext jNext i执行程序后,a 数组各元素可能是( )A.1,2,3,4,5,6 B. 1,0,3,6,5,8 C. 3,2,7,6,11,8 D.2,1,4,3,10,96.(2019年2月温州市适应性试题)有如下VB 程序段:Dim a(1 to 6) As Integer, i As IntegerRandomizeFor i = 1 To 6a(i) = Int(Rnd * 10) + 1If a(i) Mod 2 = 1 Theni = i - 1ElseIf i Mod 2 = 0 Then
6、a(i) = a(i) + a(i - 1)End IfNext i最终数组a各元素的值可能是( )A. 8,14,3,10,2,12 B. 2,4,6,10,12,24C.10,16,8,18,8,4 D. 6,12,10,20,4,87.(2019年3月绍兴适应性考试)有如下VB 程序段:a(1)= 6: a(2)= 9: a(3)= 3:a(4)= 7: a(5)= 8: a(6)= 1t = 2 * Int(Rnd * 3) + 1For i = t To 5k = iFor j = i + 1 To 6If a(j) a(k) Then k = jNext jIf k i Thent
7、 = a(i): a(i) = a(k): a(k) = tEnd IfNext i执行该程序段后,a(1)a(6)各元素的值不可能是( )A6,1,3,7,8,9 B6,9,1,3,7,8 C6,9,3,7,1,8 D1,3,6,7,8,9三、创新题组8.有如下程序段:Dim i As Integer, j As Integer, a(1 To 5) As IntegerFor i = 1 To 5a(i) = Int( Rnd * 5 + 1) For j = 1 To i-1 If a(i) = a(j) Then i = i-1 : Exit For Exit For用于强行退出For
8、循环 End If Next jNext i执行程序后,数组中数据可能是( )A1 4 3 2 5B1 1 3 5 4C1 4 5 6 3D2 3 4 5 5 9.有如下VB程序段:For i= 1 To 5a(i)= Int(Rnd * 20) + 1Next iFor i= 2 To 5If i Mod 2 = 1 And a(i-1) a(i)Then t = a(i):a(i) = a(i-1):a(i-1) = tElsea(i) = a(i) - 1End IfNext i执行该程序段后,a(1) a(5)各元素不可能的值是( )A. 7 3 0 19 0 B. 18 16 1 9
9、 2 C. 20 17 8 19 15 D. 19 0 7 8 410.有如下 VB 程序段: i = 1: n = 5 Do While i = n x = Int(Rnd * 9) + 1 If x Mod 2 = 1 Then a(i) = x Else a(n) = x n = n - 1 End If i = i + 1 Loop数组a元素的初值均为0,执行该程序段后,则a(1)至a(5)各元素值不可能的是( )A. 7 1 3 9 8 B. 3 3 0 8 8 C. 0 1 0 4 2 D. 1 3 5 5 011. 有如下VB程序段: For i = 1 To 7 a(i) =
10、Int(Rnd * 90) + 10 Next i For i = 7 To 2 Step -1 If a(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) / 2 End If Next i执行该程序段后,a(1) a(7)各元素不可能是( )A.11,73,58,62,36,37,79 B.37,74,59,63,19,40,6C.39,76,61,65,20,41,7 D.72,55,57,61,18,39,512.有VB程序段如下: Randomize For i = 1 To 6 a(i) = Int(Rnd * 20) + 1 If a(i) Mod 2 = i Mod 2 Then a(i) = a(i) - 1 Else a(i) = a(i) + 2End If Next i执行该程序段后,a(1) a(6)各元素可能的是( )A. 13,2,7,12,5,18 B. 22,7,0,15,4,19C. 20,9,18,23,4,7 D. 6,0,4,21,18,17