题型:综合题 题类:模拟题 难易度:困难
浙江省杭州市2016年信息技术高考模拟卷三
Const n As Integer = 10 'n为品牌数
Dim a(1 To n) As String '数组a用于存储品牌名称
Dim b(1 To n) As Integer '数组b用于存储销售量
Private Sub Form_Load()
'此过程用于对数组a和数组b进行赋初值,并显示在List1中,代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, x As Single, y As String
Dim n As Integer
n = 1
For i = 1 To 9
k = i
For j = i+1 To 10
If Then k = j
n=n+1
Next j
If ① Then
x = a(i): a(i) = a(k): a(k) = x
y = b(i): b(i) = b(k): b(k) = y
End If
Next i
For i = 1 To 10
List2.AddItem Str(a(i)) + " " + b(i)
Next i
Label3.Caption = "比较次数为:" + + "次"
End Sub
排序前 |
86 |
71 |
5 |
41 |
81 |
79 |
37 |
89 |
排序后 |
5 |
37 |
41 |
71 |
79 |
89 |
86 |
81 |
实现上述功能的VB代码如下,但加框处有错,请改正。
Const n=8
Dim a(1 To n)As Integer
Private Sub Commandl_Click()
Dim i As Integer,j As Integer,k As Integer,t As Integer
Dim flag As Boolean
'读取一组正整数,存储在数组a中,代码略
For i= 1 To n-1
'(1)
If IsPrime(a(k))Then flag = True Else flag = False
For j = i + 1 To n
If IsPrime(a(j)) Then
If Then '(2)
k=j
flag = True
End If
End If
Next j
If k <> i Then
t=a(k):a(k)= a(i):a(i)= t
End If
If Not flag Then Exit For 'Exit For表示退出循环
Next i
'依次输出排序后的数据。代码略
End Sub
Function IsPrime(m As Integer)As Boolean
'本函数判断m是不是素数:是素数返回值为True,不是素数返回值为False
'代码略
End Function
⑴{#blank#}1{#/blank#} ⑵{#blank#}2{#/blank#}
试题篮