修改时间:2021-05-20 浏览次数:224 类型:月考试卷
i=1:j=10
Key=Val(Text 1.Text)
If Key Mod 2=1 Then t=1 Else t=-1
Do While i<=j
m=(i+j)\2
c=c+1
If t= 1 And a(m) Mod 2= 0 Then
j=m-1
ElseIf t=- 1 And a(m) Mod 2= 1 Then
i=m+1
ElseIf Key*t<a(m) *t Then
j=m-1
Else
i=m+1
End If
Loop
若数组a(1)到a(10)的值依次为1,3,5,7,9,18,18,16,4,0,若Text 1中输入2,执行该程序段后,下列说法正确的是( )
待排序数据存储在数组a中(a(1)…a(n)),共有n个数据,要求升序排序
Dim a(0 To 100) As Integer
Dim n As Integer
Private Sub Command 1_Click()
Dim i As Integer,m As Integer
m=n\2
Do While '改错
For i=1To m
Call jpsort(i,m) '调用过程jpsort()
Next
m=m\2
Loop
'显示输出结果
End Sub
Private Sub jpsort(start As Integer,w As Integer)
For i=start To n Step w
For j= ② To i+w Step-w '填空
If a(j-w) >a(j) Then
t=a(j-w): ③ :a(j)=t '填空
End If
Next
Next
End Sub
请回答以下问题:
小陈根据上述的描述设计了以下的程序,界面如图b所示,单击“初始化”按钮Command 1,按要求生成相关数据存储在数组a中并在列表框List 1中显示,该程序中最外圈不能有地雷,单击“计算”按钮Command 2,对数组a中的数据进行计算并在列表框List 2中输出,输出数据元素的宽度为固定值。
请回答问题:
Const n=9:Const m= 10 'n存储地雷区域大小,m存储地雷数目
Dim a(1 To n*n) As Integer
Private Sub Command 1_Click()
'按要求生成数组a中的数据并在List 1中显示,代码略
End Sub
Private Sub Command 2_Click()
Dim i As Integer, j As Integer, row As Integer
Dim col As Integer, start As Integer, temp As String
For i=1 To n *n
IfThen
row=(i-1)\n+ 1
col=(i-1)Mod n+ 1
For j= 1 To 3
If a(start+col-1) >-1Then a(start+col-1) =a(start+col-1)+1
If a(start+col) >-1Then a(start+col) =a(start+col)+1
If a(start+col+1)>-1Then a(start+col+1) =a(start+col+1)+1
Next j
End If
Next i
List 2.Clear
For i=1To n
temp=“”
For j=1To n
temp=temp+adj(a((i-1) *n+j),3)
Next j
List 2.Add Item temp
Next i
End Sub
Function adj(x As Integer, y As Integer) As String
Dim s As String
s=Str(x)
For i= 1 To
s=“”+s
Next i
adj=s
End Function
试题篮