For x = 1 To 7
w = x
For y = x + 1 To 8
Next y
If w < > x Then
Temp = b(x): b(i) = b(w): b(w) = temp
End If
Next x
方框中应填入的语句为( )
st = “ ”
For i = 1 To 4
For j = 1 To 10 - i
If d(j) < d(j + 1) Then
temp = d(j): d(j) = d(j + 1): d(j + 1) = temp
End If
Next j
st = Str(d(j)) + st
Next i
Text1.Text = st
数组元素d(1)~d(10)中的数据依次为“21,8,12,16,26,71,65,89,42,36”,程序执行后,在文本框Text1中显示的内容是( )
Private Sub Command1_Click()
Dim a(1 To 100) As String, x As String, st As String
Dim i As Integer, j As Integer, n As Integer
x = Text1.Text
n = Len(Text1.Text)
For i = 1 To n
a(i) = Mid(x, i, 1)
Next i
For i = 1 To n - 1
For j = n To i + 1 Step -1
If a(j) > a(j - 1) Then
st = a(j): a(j) = a(j - 1): a(j - 1) = st
End If
Next j
Next i
st = “ ”
For i = 1 To n
st = st + a(i)
Next i
Label1.Caption = st
End Sub
程序运行时,在文本框Text1中输入“Text”(不包含双引号),单击按钮Command1,则在标签Label1上显示的内容为( )
Private Sub Command1_Click()
Dim a(10) As Integer, i As Integer
Randomize ′产生不同的随机数
For i = 1 To 10
a(i) = Int(Rnd * 100) + 1
Text1.Text = Text1.Text & Str(a(i))
Next i
Call Shaker_sort(a()) '调用Shaker_sort
For i = 1 To 10
Text2.Text = Text2.Text & Str(a(i))
Next i
End Sub
Private Sub Shaker_sort(k() As Integer)
Dim i As Integer,c As Integer,d As Integer
Dim t As Integer
c = 1
d = 10
Do While c<=d
For i= '从下往上把最小的元素移到最上面的位置
If k(i-1)>k(i) Then
t = k(i - 1):k(i- 1) = k(i):k(i) = t
End If
Next i
For i = c+1 To d-c '从上到下把最大的元素移到最下面的位置
If Then
t = k(i+1):k(i+1) = k(i):k(i) = t
End If
Next i
c = c + 1
Loop
End Sub
实现上述功能的VB程序如下,但加框处代码有错,请改正。
Const n = 10
Dim a(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer,bottom As Integer
'获取排序前数据依次存储在数组a中,并在文本框Text1中显示。代码略
bottom = n
i = 1
Do While i <= bottom - 1
For j = bottom To i + 1 Step -1
If Then '①
t = a(j): a(j) = a(j - 1): a(j - 1) = t
ElseIf a(j) = a(j - 1) Then '相邻两个数据相等,进行剔除处理
'②
bottom = bottom - 1
End If
Next j
i = i + 1
Loop
Text2.Text = “ ”
For i = 1 To bottom
Text2.Text = Text2.Text + Str(a(i))
Next i
End Sub
程序中加框①处应改正为;
加框②处应改正为。
为实现上述功能的VB程序如下,在程序划线处填入合适的代码。
Dim d(1 To 20) As Integer
Const n = 20
Private Sub Form_Load()
Dim i As Integer, j As Integer, t As Single
List1.Clear
Randomize
For i = 1 To n
List1.AddItem Str(d(i))
Next i
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t1 As Integer
For i = 1 To n - 1
For j =
If d(j) < d(j - 1) Then
t1 = d(j): d(j) = d(j - 1): d(j - 1) = t1
End If
Next j
Next i
For i = 1 To n
List2.AddItem Str(d(i))
Next i
End Sub
Private Sub Command2_Click()
Dim m As Integer
m = Val(Text1.Text)
Text2.Text = “第” + Str(m) + “ 大的数为:” +
End Sub
程序运行时,单击“生成随机数”按钮Command1,则生成20个[1,50]区间内的整数,存储在数组a中,并显示在文本框Text1中;单击“排序并去重”按钮Command2,则将数组a中数据进行从低到高排序,并将排序结果显示在文本框Text2中,将去重后结果显示在文本框Text3中,在标签Label4中显示共删除的重复数个数,程序运行界面如下图所示。
实现上述功能的VB程序如下,请回答下列问题:
Dim a(1 To 20) As Integer
Const n = 20
Private Sub Command1_Click()
Dim i As Integer, s1 As String
Randomize
s1 = “ ”
For i = 1 To n
a(i) = Int(Rnd * 50 + 1)
s1 = s1 + Str(a(i))
Next i
Text1.Text = s1
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, p As Integer, tt As Integer
Dim ans As Integer, s2 As String, s3 As String
For i = 1 To n - 1
p = i
For j = n To i + 1 Step -1
If a(j) < a(p) Then p = j
Next j
If a(i) < > a(p) Then
tt = a(i)
a(i) = a(p)
a(p) = tt
End If
Next i
s2 = “ ”:s3 = “ ”
ans = 0
For i = 1 To n
s2 = s2 + Str(a(i))
Next i
Text2.Text = s2
s3 = Str(a(1))
For i = 2 To n
If a(i) < > q Then
q = a(i)
Else
End If
Next i
Text3.Text = s3
Label4.Caption = Str(ans)
End Sub