VB程序,随机产生20个学生的成绩,并显示.统计各分数段人数,即0~59,60~69,70~79,8
答案:2 悬赏:0 手机版
解决时间 2021-03-28 02:16
- 提问者网友:爱唱彩虹
- 2021-03-27 16:02
VB程序,随机产生20个学生的成绩,并显示.统计各分数段人数,即0~59,60~69,70~79,8
最佳答案
- 五星知识达人网友:鸽屿
- 2021-03-27 17:04
Private Sub Command1_Click()
Dim a(20) As Integer
Cls
c1 = 0: c2 = 0: c3 = 0: c4 = 0: c5 = 0: c6 = 0
Randomize
Print "20个成绩:"
For i = 1 To 20
a(i) = Int(Rnd * 101)
Print a(i);
If i Mod 10 = 0 Then Print
Next i
For i = 1 To 20
If a(i) = 100 Then
c1 = c1 + 1
Else
If a(i) > 89 Then
c2 = c2 + 1
Else
If a(i) > 79 Then
c3 = c3 + 1
Else
If a(i) > 69 Then
c4 = c4 + 1
Else
If a(i) > 59 Then
c5 = c5 + 1
Else
c6 = c6 + 1
End If
End If
End If
End If
End If
Next i
Print: Print "统计结果:"
Print " 100分:"; c1
Print "90~99分:"; c2
Print "80~89分:"; c3
Print "70~79分:"; c4
Print "60~69分:"; c5
Print " 0~59分:"; c6
End Sub
或者换一种写法(运行效果完全一样):
Private Sub Command1_Click()
Dim a(20) As Integer
Dim cj(5 To 10) As Integer
Cls
Randomize
Print "20个成绩:"
For i = 1 To 20
a(i) = Int(Rnd * 101)
Print a(i);
t = a(i) 10
If t < 5 Then t = 5
cj(t) = cj(t) + 1
If i Mod 10 = 0 Then Print
Next i
Print: Print "统计结果:"
Print " 100分:"; cj(10)
Print "90~99分:"; cj(9)
Print "80~89分:"; cj(8)
Print "70~79分:"; cj(7)
Print "60~69分:"; cj(6)
Print " 0~59分:"; cj(5)
End Sub
Dim a(20) As Integer
Cls
c1 = 0: c2 = 0: c3 = 0: c4 = 0: c5 = 0: c6 = 0
Randomize
Print "20个成绩:"
For i = 1 To 20
a(i) = Int(Rnd * 101)
Print a(i);
If i Mod 10 = 0 Then Print
Next i
For i = 1 To 20
If a(i) = 100 Then
c1 = c1 + 1
Else
If a(i) > 89 Then
c2 = c2 + 1
Else
If a(i) > 79 Then
c3 = c3 + 1
Else
If a(i) > 69 Then
c4 = c4 + 1
Else
If a(i) > 59 Then
c5 = c5 + 1
Else
c6 = c6 + 1
End If
End If
End If
End If
End If
Next i
Print: Print "统计结果:"
Print " 100分:"; c1
Print "90~99分:"; c2
Print "80~89分:"; c3
Print "70~79分:"; c4
Print "60~69分:"; c5
Print " 0~59分:"; c6
End Sub
或者换一种写法(运行效果完全一样):
Private Sub Command1_Click()
Dim a(20) As Integer
Dim cj(5 To 10) As Integer
Cls
Randomize
Print "20个成绩:"
For i = 1 To 20
a(i) = Int(Rnd * 101)
Print a(i);
t = a(i) 10
If t < 5 Then t = 5
cj(t) = cj(t) + 1
If i Mod 10 = 0 Then Print
Next i
Print: Print "统计结果:"
Print " 100分:"; cj(10)
Print "90~99分:"; cj(9)
Print "80~89分:"; cj(8)
Print "70~79分:"; cj(7)
Print "60~69分:"; cj(6)
Print " 0~59分:"; cj(5)
End Sub
全部回答
- 1楼网友:迟山
- 2021-03-27 17:54
'添加窗体Form1,按钮Command1,然后添加如下代码:
Private Sub Command1_Click()
Dim s(19), a(4), i, temp As Integer
Me.AutoRedraw = True
Cls
For i = 0 To 19
Randomize
s(i) = Int(Rnd * 101)
temp = Int(s(i) / 10)
If temp = 10 Then
a(4) = a(4) + 1
ElseIf temp < 5 Then
a(0) = a(0) + 1
Else
a(temp - 5) = a(temp - 5) + 1
End If
Print s(i)
Next
Print
Print "各分数段人数分别是:" & Join(a, " ")
End Sub
Private Sub Command1_Click()
Dim s(19), a(4), i, temp As Integer
Me.AutoRedraw = True
Cls
For i = 0 To 19
Randomize
s(i) = Int(Rnd * 101)
temp = Int(s(i) / 10)
If temp = 10 Then
a(4) = a(4) + 1
ElseIf temp < 5 Then
a(0) = a(0) + 1
Else
a(temp - 5) = a(temp - 5) + 1
End If
Print s(i)
Next
Print "各分数段人数分别是:" & Join(a, " ")
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯