flag = False: n = 0
s = " Good Luck To You!"
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch >= "a" And ch <= "z" And flag Then
n = n + 1: flag = False
Else
flag = True
End If
Next i
执行该程序段后,变量 n 的值为( )
For i = 1 To 3
For j = 1 To 6 - i
If a(j) > a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = t
Next j
Next i
数组元素a(1)到a(6)的数据依次为“55,31,19,42,37,23”,则此程序运行完成后数组元素的数据依次是( )
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
数组元素的初值均为0,执行该程序段后,在下列选项中a(1)至a(5)各元素值可能的是( )
s = Text1.Text :n = Len(s)
s1 = s:i = 1
Do While i <= Len(s)
i = i + 1 Loop
Text2.Text = s1
上述程序中方框①处的可选语句有
①ch = Mid(s, i, 1)
②ch = Mid(s, n - i + 1, 1)
③s1 = s1 + ch
④s1 = ch + s1
则正确的语句为 ( )
图 b
‘函数 bw 功能:若二进制位数不足,通过在前面添"0"使得位数为 4 的倍数
Private Function bw(x As Integer, y As String) As String
Dim r As Integer, i As Integer
r = x Mod 4
If r <> 0 Then
For i = 1 To 4 - r
y = “0” + y
Next i
x = Len(y)
End If
bw = ①
End Function
Private Sub Command1_Click()
Dim m As String, n As Integer, i As Integer, a As Integer
Dim s As Integer, s1 As String, j As Integer
m = Text1.Text
n = Len(m)
Text2.Text =“”
m = ② ‘调整m的位数为4的倍数
For i = 1 To n - 3 Step 4
s = 0
For j = i To i + 3
a = Val(Mid(m, j, 1))
s = ③
Next j
If s >= 10 Then
s1 = Chr(Asc("A") + s - 10)
Else
s1 = CStr(s) ‘函数CStr类似于 Str,但无前导空格
End If
Text2.Text = Text2.Text + s1
Next i
End Sub
① ② ③
请回答下列问题:
Const n = 6
Dim a(1 To n * n) As Integer
Private Sub Form_Load() '产生 n * n 个数组元素,每行按n个数显示在 list1 中
For i = 1 To n * n
a(i) = Int(Rnd * 90) + 10
s = s + Str(a(i))
If ① Then
List1.AddItem s
s = “”
End if
Next i
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, w As Integer, s As String
For i = 1 To n * n
k = i
For j = k + n To ②
If a(k) > a(j) Then k = j
Next j
If a(k)=a(i) Then t = a(k): a(k) = a(i): a(i) = t
Next i
‘将排序后数组 a 的元素,按每行 n 个数显示在 list2 中,代码略
End Sub
① ②