抛硬币vb程序,生成n个随机数,大于0.5代表正面,小于0.5代表反面,统计多次抛硬币后,正反各多少次!
1个回答

Private Sub Command1_Click()

Dim n As Integer

Dim x As Single

Dim a As Integer, b As Integer

Dim i As Integer

n = Val(Text1)

For i = 1 To n

Randomize

x = Rnd

If x > 0.5 Then

a = a + 1

Else

b = b + 1

End If

Next i

Label3.Caption = a

Label4.Caption = b

End Sub

Private Sub Form_Load()

Text1.Text = ""

Label3.Caption = ""

Label4.Caption = ""

End Sub