.
For i = 9 To 16 Step 1 Form1.FontSize = i Print i; \号字型\ Next i End Sub
5、参考代码如下:
Private Sub Command1_Click()
Dim a(1 To 11) As Single '定义静态数组a含11个元素 Dim i, j As Integer Dim num As Single
' 给数组元素赋初值,即原始队列
a(1) = 3: a(2) = 5: a(3) = 7: a(4) = 8: a(5) = 9 a(6) = 13: a(7) = 16: a(8) = 19: a(9) = 33 a(10) = 38 ' 输出原始队列 For i = 1 To 10
Label2.Caption = Label2.Caption & a(i) & \ Next i
num = Val(Text1.Text) ' 把输入的数插入队列中 For i = 10 To 1 Step -1 If num < a(i) Then
a(i+1) = a( i ) ' 元素后移一个位置 else
a(i+1) = num
Exit For ' 退出循环 End If Next i ' 输出新队列 For i = 1 To 11
36 / 52
.
Label3.Caption = Label3.Caption & a(i) & \ Next i End Sub
6、参考代码如下:
Option Base 1
Private Sub Form_Load()
Const N = 4 ' 常量N决定二维数组大小 Dim a(N, N) As Integer Dim i, j, Temp As Integer Show ' 数组初始化
For i = 1 To N ' For循环 i从1变化到N For j = 1 To N a(i, j) = i * 10 + j Next j Next i ' 输出原始数组
Print \转置前的数组:\
For i = 1 To N ' For循环 i从1变化到N For j = 1 To N Print a(i, j); Next j Print Next i ' 数组转置
For i = 1 To N ' For循环 i从1变化到N For j = 1 To i ' 交换 Temp = a(i, j) a(i, j) = a(j, i) a(j, i) = Temp
37 / 52
.
Next j Next i
' 输出转置后的数组 Print \转置后的数组:\
For i = 1 To N ' For循环 i从1变化到N For j = 1 To N Print a(i, j); Next j Print Next i End Sub
7、参考代码如下:
Private Sub Form_Click()
Dim a(10) As Integer, i As Integer Dim sum As Integer, ave As Integer sum = 0 For i = 1 To 10
a(i) = Int(Rnd * 101) sum = sum + a(i) Next i ave = sum / 10 Print sum, ave End Sub
8、参考代码如下:
Private Sub Form_Load() Dim i, j, k, Flower As Integer Show For i = 1 To 9 For j = 0 To 9 For k = 0 To 9
38 / 52
.
Flower = i * 100 + j * 10 + k
If Flower = i ^ 3 + j ^ 3 + k ^ 3 Then Print Flower ; \是水仙花数\
Next k Next j Next i End Sub
9、程序参考代码如下:
Private Sub Command1_Click() Dim m, i, y As Integer m = Val(Text1.Text) If m <= 2 Then
Label2.Caption = \输入数据有错\ Else
k = Sqr(m) + 1 For i = 2 To k y = m Mod i If y = 0 Then Exit For Next i If y = 0 Then
Label2.Caption = m & \不是素数\ Else
Label2.Caption = m & \是素数\ End If End If End Sub
10、程序参考代码如下:
Option Base 1
Private Sub Form_Load()
Const N = 5 ' 常数 N 确定数组的大小
39 / 52
.
Dim a(N, N) As Integer
Dim i, j, row, line, min As Integer Show
For i = 1 To N ' For循环 i从1变化到N For j = 1 To N ' For循环 j从1变化到N a(i, j) = Int(100 * Rnd) + 1 ' 产生N*N个1~100间的随机数 Next j Next i ' 输出二维数组 Print \数组内容是:\ For i = 1 To N For j = 1 To N Print a(i, j); Next j
Print ' 输完一行元素后输出一个换行 Next i ' 设定初始值
min = a(1, 1): row = 1: line = 1 ' 寻找最小数 For i = 1 To N For j = 1 To N
If a(i, j) < min Then min = a(i, j) row = i line = j End If Next j Next i ' 输出结果
Print \最小值是:\
40 / 52