产生随机数 vb
发布网友
发布时间:2024-10-12 11:25
我来回答
共1个回答
热心网友
时间:2024-10-14 12:20
Dim a(1 To 80) As Integer
Dim er(1 To 80) As Integer
Dim ji(1 To 80) As Integer
Dim k, n, i As Integer
n = 0
k = 0
For i = 1 To 80
a(i) = Int((99 - 10 + 1) * Rnd + 10) ' 生成 10 到 99 之间的随机数值。
If a(i) Mod 2 = 0 Then '如果是偶数
k = k + 1
er(k) = a(i)
Else '否则是奇数
n = n + 1
ji(n) = a(i)
End If
Next i
'以下把得到的数据显示出来
Dim s As String
Print "奇数的个数为:" & n & vbCrLf
Print "生成的奇数有:"
For i = 1 To n
s = s & ji(i) & " "
Next i
Print s
Print vbCrLf '换行
s = ""
Print "偶数的个数为:" & k
Print "生成的偶数有:"
For i = 1 To k
s = s & er(i) & " "
Next i
Print s
Print vbCrLf
Print vbCrLf
'把上面代码复制到Command1_Click 里,点击就可以了,记得窗体要大一些
'也可以把Print 换成Debug.Print ,然后在立即窗口里可以看到结果