vb随机产生n(20到80)个两位整数,不用box产生,然后存到一维数组中!
1个回答
展开全部
Private Sub Command1_Click()
Dim a() As Integer '声明一个动态数组
Dim i As Integer, n As Integer
Dim str As String
Randomize
'生成一个随机整数n(20≤n≤100)
n = Int((100 - 20 + 1) * Rnd + 20)
ReDim a(1 To n)
'产生n个1-1000的随机数并写入数组
For i = 1 To n
a(i) = Int(1000 * Rnd + 1)
str = str & a(i) & " "
If i Mod 10 = 0 Then str = str & vbCrLf '令每10个随机数显示为一行
Next i
Me.Cls '清空窗体上显示的旧随机数
Print str '窗体显示新生成随机数
Print ""
Print "***本次共生成" & n & "个 1到1000之间的随机整数***"
End Sub
Dim a() As Integer '声明一个动态数组
Dim i As Integer, n As Integer
Dim str As String
Randomize
'生成一个随机整数n(20≤n≤100)
n = Int((100 - 20 + 1) * Rnd + 20)
ReDim a(1 To n)
'产生n个1-1000的随机数并写入数组
For i = 1 To n
a(i) = Int(1000 * Rnd + 1)
str = str & a(i) & " "
If i Mod 10 = 0 Then str = str & vbCrLf '令每10个随机数显示为一行
Next i
Me.Cls '清空窗体上显示的旧随机数
Print str '窗体显示新生成随机数
Print ""
Print "***本次共生成" & n & "个 1到1000之间的随机整数***"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询