Print Next i
Max = mat(1, 1) For i = 1 To n For j = 1 To m
'**********SPACE********** If 【?】 Then Max = mat(i, j) col = j
'**********SPACE********** 【?】 End If Next j Next i Print
Print \矩阵最大的元素的值为:\Print \它所在的行号为:\列号为:\End Sub
(答案) ReDim mat(n, m) As Integer mat(i, j) > Max row = I
'-------------------------------------------------------
'功能:本程序利用二分法查找某数字n是否在已排序的数列当中, ' 若在其中则输出其在数列中的位置,否则输出-1。 '------------------------------------------------------- Option Base 1
Sub birsearch(a(), ByVal low%, ByVal high%, ByVal key, index%) Dim mid As Integer mid = (low + high) \\ 2 If a(mid) = key Then
'**********SPACE********** 【?】 Exit Sub
ElseIf low > high Then index = -1 Exit Sub End If
If key < a(mid) Then
'**********SPACE********** high = 【?】 Else
low = mid + 1 End If
'**********SPACE**********
Call birsearch(a(), low, high, 【?】, index) End Sub
Private Sub Command1_Click()
Dim b() As Variant, index As Integer
b = Array(5, 13, 19, 21, 37, 56, 64, 75, 80, 88, 92) n = Val(Text1)
Call birsearch(b, LBound(b), UBound(b), n, index) Print index End Sub
(答案) index = mid mid – 1 key
'-------------------------------------------------------
'功能:单击“插入数据”按钮后,输入一个整型数据,
' 该数据会被插入到一个有序的数组a(1 to 10)中,插入该数据后数组还是有序的。 '------------------------------------------------------- Option Base 1
Private Sub Command1_Click() Dim a%(1 To 10), i%, k%, m% Print \原数列是\ For i = 1 To 9
a(i) = (i - 1) * 3 + 1 Print a(i); Next i Print
m = Val(InputBox(\输入要插入的数据\ For k = 1 To 9
'**********SPACE********** If (m < a(k)) Then 【?】 Next k
For i = 9 To k Step -1
'**********SPACE********** a(【?】) = a(i) Next i
'**********SPACE********** a(k) = 【?】
Print \插入\后的数列是:\ For i = 1 To 10 Print a(i); Next i Print End Sub
(答案) Exit For i+1 m
'-------------------------------------------------------
'功能:写出程序运行时单击窗体后,Form1上的输出结果 ' x(1) = 8 ' x(2) = 6 ' x(3) = 4 ' x(4) = 3 ' x(5) = 1
'------------------------------------------------------- Private Sub Form_Click()
Dim x(5) As Integer
'**********SPACE********** Dim i, j, t,【?】 As Integer x(1) = 8 x(2) = 3 x(3) = 1 x(4) = 6 x(5) = 4
For i = 1 To 4
For j = i + 1 To 5
'**********SPACE**********
If x(i) 【?】 x(j) Then t = x(i): x(i) = x(j): x(j) = t Next j, i
'**********SPACE********** For k = 1 To 【?】
Form1.Print \ Next k End Sub
(答案) K < 5
'-------------------------------------------------------
'功能:以下程序段用于输出杨辉三角:结果样式如图1 '------------------------------------------------------- Private Sub Form_Click() Const n = 10
Dim arr(n, n) As Integer For I = 1 To n arr(I, I) = 1
'**********SPACE********** 【?】 Next I
For I = 3 To n
For j = 2 To I - 1
'**********SPACE********** arr(i, j) =【?】 Next j Next I
For I = 1 To n For j = 1 To I
'**********SPACE********** ? 【?】& \ Next j Print Next I End Sub
(答案) arr(i, 1) = 1 arr(i - 1, j - 1) + arr(i - 1, j) arr(i, j)
六.文件
'-------------------------------------------------------
'功能:本程序执行后,最终在窗体上打印数字7。 '------------------------------------------------------- Private Sub Command1_Click() Dim a As String
'**********SPACE**********
Open App.Path & \【?】 As #1 n = 8
For I = 1 To n Print #1, I + 1 Next I Close #1
'**********SPACE**********
Open App.Path & \【?】 As #1 For I = 1 To n Input #1, a
If I Mod 5 = 0 Then
'**********SPACE********** Print CInt(a) + 【?】 End If Next I Close #1 End Sub
(答案) Output Input 1
'-------------------------------------------------------
'功能:本程序求3~100之间的所有素数(质数)并统计个数; ' 同时将这些素数从小到大依次写入顺序文件 dataout.txt; ' 素数的个数显示在窗体Form1上。 '------------------------------------------------------- Private Sub Command1_Click()
Dim count As Integer, flag As Boolean Dim t1 As Integer, t2 As Integer '**********SPACE**********
Open App.Path & \【?】 count = 0
For t1 = 3 To 100
'**********SPACE********** flag = 【?】
For t2 = 2 To Int(Sqr(t1))
If t1 Mod t2 = 0 Then flag = False Next t2 If flag Then
'**********SPACE********** count = 【?】 Write #1, t1
End If Next t1
Form1.Print \素数个数\ Close #1 End Sub
(答案) #1 True count + 1
'-------------------------------------------------------
'功能:窗体中有两个List列表,及4个按钮。程序功能,单击
“产生随机数”按钮,随机产生20个随机数填入List1中 ' “保存”按钮 作用是将数组内容写到文件中 ' “读出”按钮 作用是将文件内容读到数组中 ' “结束”按钮 作用是结束程序
'------------------------------------------------------- Dim d(1 To 20) As Integer
Private Sub Command1_Click() '\产生随机数\ Dim i As Integer List1.Clear For i = 1 To 20
'**********SPACE********** d(i) = Int(1 + 99 *【?】) List1.AddItem d(i) Next i End Sub
Private Sub Command2_Click() '\保存\ Dim i As Integer
Open App.Path & \ For i = 1 To 20
'**********SPACE********** Write 【?】, d(i) Next i Close #1 End Sub
Private Sub Command3_Click() '\读出\ Dim x As String
Open App.Path & \ List2.Clear
'**********SPACE********** Do While Not 【?】 Input #1, x
List2.AddItem x Loop Close #1 End Sub
Private Sub Command4_Click() '\结束\ End End Sub
(答案) Rnd #1 EOF(1)