VB 编写程序,生成10个无重复数(即互不相等)的两位随机数Private Sub Command1_Click()Dim a(10) As Integer,n As IntegerDim i As Integer,k As IntegerRandomizea(1) = Int(Rnd * 90) + 10k = 1Don=___for____if____then exit forNext iif _
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 07:52:41
VB 编写程序,生成10个无重复数(即互不相等)的两位随机数Private Sub Command1_Click()Dim a(10) As Integer,n As IntegerDim i As Integer,k As IntegerRandomizea(1) = Int(Rnd * 90) + 10k = 1Don=___for____if____then exit forNext iif _
VB 编写程序,生成10个无重复数(即互不相等)的两位随机数
Private Sub Command1_Click()
Dim a(10) As Integer,n As Integer
Dim i As Integer,k As Integer
Randomize
a(1) = Int(Rnd * 90) + 10
k = 1
Do
n=___
for____
if____then exit for
Next i
if ___ then
k=____
a(k) = n
End If
loop ___
For i = 1 To 10
Text1 = Text1 & Str(a(i))
Next i
End Sub
帮我补充一下
VB 编写程序,生成10个无重复数(即互不相等)的两位随机数Private Sub Command1_Click()Dim a(10) As Integer,n As IntegerDim i As Integer,k As IntegerRandomizea(1) = Int(Rnd * 90) + 10k = 1Don=___for____if____then exit forNext iif _
两种方法
1 补充你的算法,
Private Sub Command1_Click()
Dim a(10) As Integer,n As Integer
Dim i As Integer,k As Integer
Randomize
a(1) = Int(Rnd * 90) + 10
k = 1
Do
n = Int(Rnd * 90) + 10
For i = 1 To 10
If a(i) = n Then Exit For
Next i
If i > 10 Then
k = k + 1
a(k) = n
End If
Loop While k < 10
For i = 1 To 10
Text1 = Text1 & Str(a(i))
Next i
End Sub
2利用集合
Private Sub Command1_Click()
Dim Zjh As New Collection
Dim Tempjh As New Collection
Dim i As Integer,k As Integer
For i = 10 To 99
Zjh.Add i
Next
For i = 1 To 10
Randomize
k = Int(Rnd() * Zjh.Count + 1)
Tempjh.Add Zjh(k)
Zjh.Remove k
Next
For i = 1 To Tempjh.Count
Text1 = Text1 & Tempjh(i)
Next
End Sub