随机生成100个两位整数,并统计出其中小于等于40、大于40且小于等于70及大于70的数据个数。
解,此题VB代码如下:
Option Base 1
Private Sub Form_Click()
Dim a(100) As Integer, i As Integer, m As Integer, n As Integer, k As Integer
Cls’先清屏
Print “生成100个两位随机整数”
For i = 1 To 100
a(i) = Int(Rnd * 90) + 10
Print a(i);
If i Mod 10 = 0 Then Print ‘一行只输出10个
m = 0: n = 0: k = 0
For i = 1 To 100
If a(i) <= 40 Then
m = m + 1
ElseIf a(i) > 40 And a(i) <= 70 Then
n = n + 1
Else
k
Print “统计情况:”
Print “小于等于40的数有”; m
Print “小于等于70的数有”; n
Print “大于70的数有”; k
End Sub
于等于70的数有”; n
Print “大于70的数有”; k
End Sub
运行程序,点击窗体,此题程序运行效果图如下: