题型:单选题 题类:常考题 难易度:普通
浙江省浙南名校联盟2020届高三上学期信息技术第一次(10月)联考试卷
For i = 1 To 2
For j = 1 To 6 - i
If a(j) - a(j + 1) > 0 Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i Text1.Text = "" For i = 1 To 6
Text1.Text = Str(a(i)) + Text1.Text Next i
数组元素a(1)到a(6)的初值依次为15,11,58,38,26,9,执行该程序段,文本框Text1显示的内容是( )
排序前 |
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 Command1_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(i))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
排序前 |
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
试题篮