VB题随机生成100个两位数整数,并统计出小于等于40,大于等于70 及大于70的数据个数
答案:2 悬赏:30 手机版
解决时间 2021-04-07 20:50
- 提问者网友:末路
- 2021-04-07 15:00
VB题随机生成100个两位数整数,并统计出小于等于40,大于等于70 及大于70的数据个数
最佳答案
- 五星知识达人网友:纵马山川剑自提
- 2021-04-07 16:11
Private Sub Command1_Click()
Dim suzu(100) As Integer
Randomize
For i = 1 To 100
suzu(i) = Rnd * 89 + 10
Next
For i = 1 To 100
Select Case suzu(i)
Case 0 To 40
n40 = n40 + 1
Case 70
n70 = n70 + 1
Case 71 To 100
n71 = n71 + 1
End Select
Next
Print "小于40的个数:"; n40
Print "大于等于70 的个数:"; n70 + n71
Print "大于70的个数:"; n71
End Sub
Dim suzu(100) As Integer
Randomize
For i = 1 To 100
suzu(i) = Rnd * 89 + 10
Next
For i = 1 To 100
Select Case suzu(i)
Case 0 To 40
n40 = n40 + 1
Case 70
n70 = n70 + 1
Case 71 To 100
n71 = n71 + 1
End Select
Next
Print "小于40的个数:"; n40
Print "大于等于70 的个数:"; n70 + n71
Print "大于70的个数:"; n71
End Sub
全部回答
- 1楼网友:爱难随人意
- 2021-04-07 17:02
Private Sub Command1_Click()
Dim s(100) As Long
For i = 1 To 100
Randomize
s(i) = Int(Rnd() * 90) + 10(因为随机函数是0.9999..乘方的,所以取整不会出现90+10)
Next i
For j = 1 To 100
Select Case s(j)
Case Is < 40
xy40 = xy40 + 1
Case Is >= 70
dydy = dydy + 1
End Select
Next j
Print "随机产生数中小于40的有: " & xy40
Print "随机产生数中等于及大于70的有: " & dydy
End Sub
Dim s(100) As Long
For i = 1 To 100
Randomize
s(i) = Int(Rnd() * 90) + 10(因为随机函数是0.9999..乘方的,所以取整不会出现90+10)
Next i
For j = 1 To 100
Select Case s(j)
Case Is < 40
xy40 = xy40 + 1
Case Is >= 70
dydy = dydy + 1
End Select
Next j
Print "随机产生数中小于40的有: " & xy40
Print "随机产生数中等于及大于70的有: " & dydy
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯