题型:综合题 题类:常考题 难易度:困难
浙江省安吉县上墅私立高级中学2015-2016学年高二下学期期中考试试卷信息技术部分
实现上述功能的VB代码如下,但划线处代码有错,请改正。
Const n As Integer = 10
Dim a(1 To n) As Integer
Private Sub Form_Load()
Dim i As Integer
Randomize
For i = 1 To n
a(i) = Int(Rnd * 100)
List1.AddItem Str(a(i))
Next
End Sub
Private Sub Command1_Click()
Dim tmp As Integer, i As Integer, j As Integer, k As Integer
For i = 1 To n - 1
k = 0
For j = n To i + 1 Step -1
If a(j) > a(j - 1) Then
tmp = a(j): a(j - 1) = a(j): a(j) = tmp
k = k + 1
End If
Next j
If k > 0 Then i = n
Next i
For i = 1 To n
List2.AddItem Str(a(i))
Next i
End Sub
End Sub
排序前 |
71 |
85 |
64 |
55 |
42 |
62 |
33 |
17 |
34 |
30 |
排序后 |
71 |
85 |
17 |
55 |
33 |
30 |
62 |
42 |
34 |
64 |
实现上述功能的VB程序如下,但加框处代码有错,请改正。
Const n=10
Dim a(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer,j As Integer
Dim temp As Integer,flag As Boolean
'读取一组正整数,存储在数组a中,代码略
i=1:j=n
temp=a(j):flag=True
Do While i<j
If flag Then
If a(i) Mod 2=0 Then
a(j)=a(i)
j=j-1
flag=Not flag
Else
'{#blank#}1{#/blank#}
End If
Else
If a(j) Mod 2=1 Then
a(i)=a(j)
flag=Not flag
Else
j=j-1
End If
End If
Loop
' {#blank#}2{#/blank#}
'依次输出排序后的数据,代码略。
End Sub
试题篮