'【程序填空】
'-------------------------------------------------------
'功能:下面的程序段用于实现以下功能:利用冒泡法将一组整数 ' 从小到大排序。
'------------------------------------------------------- Private Sub Form_Click() Const n = 15
Dim a(1 To n) As Integer, work As Boolean Dim i As Integer, j As Integer, x As Integer Randomize For i = 1 To n
a(i) = Int((90 * Rnd) + 10) Next i
For i = 1 To n Print a(i); Next i Print
'**********SPACE********** For i = n To 2 【?】step-1 work = True For j = 1 To i - 1
If a(j) > a(j + 1) Then
x = a(j): a(j) = a(j + 1): a(j + 1) = x '**********SPACE********** 【?】work=False End If Next j
'**********SPACE********** If work Then 【?】Exit For Next i
For i = 1 To n Print a(i); Next i End Sub 答案
1). Step -1
2). work = False 或 work=0 或 not work = true 3). Exit For
'功能:以下程序用于判断一个正整数(≥3)是否为素数。
'-------------------------------------------------------
Private Sub Form_Click()
n = InputBox(\请输入一个正整数(≥3)\k = Int(Sqr(n)) i = 2 swit = 0
'**********SPACE********** Do While i <= k And 【?】swit=0 '**********SPACE********** If 【?】n Mod i =0 Then swit = 1 ?不是素数 Else
'**********SPACE********** 【?】i = i + 1 End If Loop
If swit = 0 Then
Print n; \是一个素数\Else
Print n; \不是素数\End If End Sub
答案:
1). swit = 0
2). n Mod i = 0 或 n/i ★= ★ n\\i 或 n/i ★=★ int(n/i) 3). i = ★i ★+★ 1
'功能:本程序用于实现:从键盘接收一数字,判断其是否在数组 ' 中,如果在数组中则将其删除,否则显示该数字不在数组 ' 中。
'------------------------------------------------------- Private Sub Form_Click()
Dim a(10) As Integer, x As Integer For i = 1 To 10
a(i) = Int((Rnd * 90) + 10) Print a(i); Next i Print
x = InputBox(\请输入要删除的整数\For i = 1 To 10
'**********SPACE********** If a(i) = x Then 【?】Exit For Next i
'**********SPACE**********
If 【?】i< 10 Then For k = i To 9
'**********SPACE********** 【?】a(k) = a( k + 1 ) Next k
Print \删除后的数组:\ For i = 1 To 9 Print a(i); Next i Else
Print \该数字不在数组中\End If End Sub
答案:
1). Exit For
2). i<10 或 10>i
3). a(k) = a(★ k ★+ ★1★)
'功能:利用下面的过程求m!和m*n
'------------------------------------------------------- Private Sub Form_Click()
Dim m As Integer, n As Integer m = 2 n = 3
'**********SPACE********** 【?】call find(m,n) End Sub
Private Sub find(x As Integer, y As Integer) Dim s, i As Integer
'**********SPACE********** 【?】s=1 For i = 1 To x s = s * i
'**********SPACE********** p=【?】x*y Next i Print s, p End Sub
答案:
1). find m, n 或 call find(m,n) 2). s = 1 或 s = 1:p=0 3). p★+★y 或 x*y