生成100个-10到10之间的随机整数,存于数组A中,统计这100个数中-10,-5,5,10的个数。
答案:1 悬赏:60 手机版
解决时间 2021-02-06 17:12
- 提问者网友:贪了杯
- 2021-02-05 19:10
大神,急求问怎么编程VB
最佳答案
- 五星知识达人网友:轻雾山林
- 2021-02-05 20:04
Private Sub Form_Click()
Dim a(1 To 100) As Integer
Dim a5 As Integer, a10 As Integer, a_5 As Integer, a_10 As Integer
Randomize
For i = 1 To 100
a(i) = Int(Rnd() * 21) - 10
If a(i) = 5 Then
a5 = a5 + 1
ElseIf a(i) = 10 Then
a10 = a10 + 1
ElseIf a(i) = -5 Then
a_5 = a_5 + 1
ElseIf a(i) = -10 Then
a_10 = a_10 + 1
End If
Next i
Print "这100个数中"
Print "-10的个数:" & a_10
Print "-5的个数:" & a_5
Print "5的个数:" & a5
Print "10的个数:" & a10
End Sub
Dim a(1 To 100) As Integer
Dim a5 As Integer, a10 As Integer, a_5 As Integer, a_10 As Integer
Randomize
For i = 1 To 100
a(i) = Int(Rnd() * 21) - 10
If a(i) = 5 Then
a5 = a5 + 1
ElseIf a(i) = 10 Then
a10 = a10 + 1
ElseIf a(i) = -5 Then
a_5 = a_5 + 1
ElseIf a(i) = -10 Then
a_10 = a_10 + 1
End If
Next i
Print "这100个数中"
Print "-10的个数:" & a_10
Print "-5的个数:" & a_5
Print "5的个数:" & a5
Print "10的个数:" & a10
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯