vb随机产生30个0-9的数字,调用过程countn(a(),count)统计字符串中数字出现次数 5
1个回答
展开全部
Dim a(29) As Integer '存放数组
Dim i As Integer '循环变量
Dim c As Integer '出现次数
Sub 生成随机数()
Randomize
For i = 0 To 29 '30个
a(i) = Int(Rnd() * 10) '0~9
Print a(i);
Next
Print
End Sub
Function countn(n, count As Integer) As Integer
For i = 0 To UBound(n)
If n(i) = count Then countn = countn + 1
Next
End Function
Private Sub Command1_Click()
Call 生成随机数
c = 5
MsgBox c & "出现了" & countn(a(), c) & "次"
End Sub
Dim i As Integer '循环变量
Dim c As Integer '出现次数
Sub 生成随机数()
Randomize
For i = 0 To 29 '30个
a(i) = Int(Rnd() * 10) '0~9
Print a(i);
Next
End Sub
Function countn(n, count As Integer) As Integer
For i = 0 To UBound(n)
If n(i) = count Then countn = countn + 1
Next
End Function
Private Sub Command1_Click()
Call 生成随机数
c = 5
MsgBox c & "出现了" & countn(a(), c) & "次"
End Sub
参考资料: VB探讨超级群 48029944
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询