1.下列程序随机产生n个互不重复的三位数,存放在数组a中,从键盘输入要随机产生的数据的个数,数据以每行4个的形式输出,同时调用子过程s( ),将统计的结果输出。子过程s( )的功能是统计数组x中百位数与个位数相同的个数。
Private Sub Button1_Click(......) Handles Button1.Click
Dim a%(), c%, k%, n%, j%, i%, count%
Dim Flag As Boolean
k = Val(InputBox("输入产生数的个数:"))
______(1)_____
a(0) = Int(Rnd() * 900 + 100)
n = 1
Do While n < k
c = Int(Rnd() * 900 + 100)
Flag = True
For j = 0 To n - 1
If a(j) = c Then _____(2)_____
Next j
If Flag Then ' 没有找到,产生的字母非重复,存放到数组中
a(n) = c : n = n + 1
End If
Loop
For i = 0 To k - 1
Label1.Text &= a(i) & " "
If _____(3)_____ Then Label1.Text &= vbCrLf
Next i
Call s(a, count)
Label1.Text &= vbCrLf & "满足条件的个数:" & count
End Sub
Sub s(_____(4)_____) '要求严格区分是传值还是传地址
Dim i, k As Integer, f As Boolean
For i = 0 To ______(5)_______
k = x(i)
If k \ 100 = k Mod 10 Then count = count + 1
Next
End Sub
2.程序运行后,在列表框中产生16个80到110之间间隔为2的华氏温度及其对应的摄氏温度表。单击按钮,要求从键盘输入一个华氏温度,在列表框中的查找,若找到,将找到的信息输出,否则,输出"找不到"。
Private Sub Form1_Load(......) Handles MyBase.Load
Dim f%, c%
ListBox1.Items.Clear()
ListBox1.Items.Add("华氏 摄氏")
For f = 80 To 110 Step 2
c = 5 / 9 * (f - 32) '求摄氏温度
ListBox1._______(1)_______(f & Space(10 - Len(Str(f))) & c)
Next
End Sub
Private Sub Button1_Click(......) Handles Button1.Click
Dim d%, i%, f%, c%, x$
Dim flag As Boolean
d = Val(InputBox("输入要查找的华氏温度"))
flag = False
For i = 0 To ListBox1._______(2)_______
x = ListBox1.Items(i)
f = Val(Mid(x, 1, 3))
If f = d Then
_______(3)_______
Exit For
End If
Next
If flag Then
MsgBox("华氏:" & f & vbCrLf & "摄氏:" & Microsoft.VisualBasic.Right(x, 2))
Else
MsgBox("找不到!")
End If
End Sub