VB编程,用随机函数产生100个【0,99】范围内的随机整数,统计个位上的数字为0的元素个数
问题描述:
VB编程,用随机函数产生100个【0,99】范围内的随机整数,统计个位上的数字为0的元素个数
答
窗体上放个CommandButton和两个Label:
Private Sub Command1_Click()
Dim i As Integer,j As Integer,n As Integer
Label1.Caption = ""
Randomize
For i = 0 To 99
j = Int(Rnd * 99)
If j Mod 10 = 0 Then n = n + 1
Label1.Caption = Label1.Caption & " " & j
Next i
Label2.Caption = "个位数为0的元素个数:" & n
End Sub