Next i Print
Print \End Sub
26、利用随机函数生成一个4×4的矩阵(即二维矩阵),范围是[20,50]内的整数,输出每行中的最大值和下标。
Dim a%(3, 3), i%, j%, imax% Private Sub Command1_Click() For i = 0 To 3 For j = 0 To 3
a(i, j) = Int(Rnd * 31 + 20) Picture1.Print a(i, j); \ Next j
Picture1.Print Next i imax = 0
For i = 0 To 3 For j = 0 To 3
If a(i, imax) < a(i, j) Then imax = j End If Next j
Picture2.Print \第\行\最大值为\下标为\ Next i End Sub
27、声明一个整型的二维数组a(1 to 4,1 to 4),用随机函数产生各元素,范围介于[1,20]之间,编程将第1行和第3行对应元素交换。 Private Sub Form_Click() Dim a%(1 To 4, 1 To 4), i%, j% Print \排序前\For i = 1 To 4 For j = 1 To 4
a(i, j) = Int(Rnd * 20 + 1) Print Tab(j * 4); a(i, j); Next j Print Next i
Print \排序后\For j = 1 To 4
t = a(1, j): a(1, j) = a(3, j): a(3, j) = t Next j
For i = 1 To 4
For j = 1 To 4
Print Tab(j * 4); a(i, j); Next j Print Next i End Sub
28.编写一个过程计算并输出区间[100,1000]内所有素数的和(要求判断素数使用过程(函数或子过程)来实现)。调用该过程。(提示:只能被1 和自身整除的自然数成为素数) Function sushu%(ByVal x%) Dim m%, Tag As Boolean, i% m = Val(x) Tag = True
For i = 2 To m - 1
If (m Mod i) = 0 Then Tag = False Next i
If Tag Then sushu = x End Function
Private Sub Command1_Click() Dim i%, k%
For i = 100 To 1000
If sushu(i) Then List1.AddItem i Next i Sum = 0
For k = 0 To List1.ListCount - 1 Sum = Sum + Val(List1.List(k)) Next k
Label1 = \[100,1000]内所有素数和为:\End Sub
29,30、随机生成一个整型的二维数组,范围在[10,20]之间,以下三角形式输出该数组。 Private Sub Form_Click() Dim a(4, 4) As Integer For i = 0 To 4 For j = 0 To 4
a(i, j) = Int(Rnd * 11 + 10) Next j Next i
For i = 0 To 4 For j = 0 Toi Print a(i, j); Next j Print
Next i End Sub
以上三角形式输出该数组 Dim a%(4, 4)
Private Sub Command1_Click() Picture1.Cls For i = 0 To 4 For j = i To 4
Picture1.Print Tab(j * 6); a(i, j); Next j
Picture1.Print Next i End Sub
Private Sub Form_Load() For i = 0 To 4 For j = 0 To 4
a(i, j) = Int(Rnd * 11 + 10) Next j Next i End Sub
31、利用随机函数生成一个4×4的矩阵(即二维矩阵),范围是[40,80]内的整数,求它的最大值及所对应的下标。 Private Sub Form_Click() Dim a(3, 3), max%, imax% For i = 0 To 3 For j = 0 To 3
a(i, j) = Int(Rnd * 41 + 40) Next j Next i
For i = 0 To 3 For j = 0 To 3 Print a(i, j); Next j Print Next i
For i = 0 To 3 For j = 0 To 3