将一个六面正方体抛出100次,统计正方体落地后每一面向上的次数。求VB 代码!!在线等
3个回答
展开全部
Dim XX As Integer
Private Sub Command1_Click()
Text1.Text = ""
XX = XX + 1
Text1.Text = "第" & XX & "次统计结果:" & vbCrLf
Dim a(1 To 100) As Integer, B(1 To 6) As Integer
For I = 1 To 100
Randomize
a(I) = Int(6 * Rnd + 1)
Select Case a(I)
Case 1: B(1) = B(1) + 1
Case 2: B(2) = B(2) + 1
Case 3: B(3) = B(3) + 1
Case 4: B(4) = B(4) + 1
Case 5: B(5) = B(5) + 1
Case 6: B(6) = B(6) + 1
End Select
Next I
For I = 1 To 6
Text1.Text = Text1.Text & "第" & I & "面向上:" & CStr(B(I)) & "次。" & vbCrLf
Next I
End Sub
Private Sub Form_Load()
XX = 0
End Sub
展开全部
一个按钮:
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
Dim MyValue As Integer
Dim d(1 To 6) As Integer
For i = 1 To 6
d(i) = 0
Next i
Randomize
For i = 1 To 100
MyValue = Int((6 * Rnd) + 1) ' 生成 1 到 6 之间的随机数值。
d(MyValue) = d(MyValue) + 1
Next i
'输出结果
For i = 1 To 6
Print "第" & CStr(i) & "面向上的次数为:" & CStr(d(i))
Next i
Print
End Sub
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
Dim MyValue As Integer
Dim d(1 To 6) As Integer
For i = 1 To 6
d(i) = 0
Next i
Randomize
For i = 1 To 100
MyValue = Int((6 * Rnd) + 1) ' 生成 1 到 6 之间的随机数值。
d(MyValue) = d(MyValue) + 1
Next i
'输出结果
For i = 1 To 6
Print "第" & CStr(i) & "面向上的次数为:" & CStr(d(i))
Next i
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
逐次产生范围1--6的随机数,代表各个面,对应计数器累加即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询