五笔打字通主页
10.编写程序,随机生成100个两位整数,并统计出其中小于等于40、大于40且小于等于70及大于70的数据个数。----wb86.com
解,此题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个数据
Next i
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 = k + 1
End If
Next i
Print "统计情况:"
Print "小于等于40的数有"; m
Print "小于等于70的数有"; n
Print "大于70的数有"; k
End Sub
运行程序,点击窗体,此题程序运行效果图如下:
---- 新编Visual Basic程序设计教程 答案 陈斌 著
来源:济亨网
本文链接:https://wb98.com/post/155.html