题型:填空题 题类:常考题 难易度:困难
浙江省信息技术名师预测冲刺卷(一)
实现上述功能的VB程序如下,但加框处代码有错,请改正。
Const n=10
Dim a(1 To n)As Integer
Private Sub Form_Load()
‘获取排序前数据,并依次存储在数组a中,并在文本框Text1中显示。代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer,j As Integer,t As Integer
Dim top As Integer
top=1
For i=1 To n-1
For j= To n-1 ‘⑴
If a(i)>a(j+1)Then
t=a(j):a(j)=a(j+1):a(j+1)=t
ElseIf a(j)=a(j+1)Then ‘相邻两个数据相等,由前面数据对进行覆盖处理
‘⑵
top=top+1
End If
Next j
Next i
Text2.Text=“ ”
For i=top To n
Text2.Text=Text2.Text+Str(a(i))
Next i
End Sub
试题篮