VB编程实现:单击命令按钮Command1,随机产生50个[1,100]之间的整数,在窗体输出其中
VB编程实现:单击命令按钮Command1,随机产生50个[1,100]之间的整数,在窗体输出其中的最大值、最小值和平均值...
VB编程实现:单击命令按钮Command1,随机产生50个[1,100]之间的整数,在窗体输出其中的最大值、最小值和平均值
展开
1个回答
展开全部
Private Sub Command1_Click()
Dim intA(0 To 49) As Integer
Dim i As Integer
Dim j As Integer
Dim s As Integer
Dim Flag As Boolean
Dim Temp As Integer
Randomize
For i = 0 To 49
intA(i) = Int(100 * Rnd) + 1
s = s + intA(i)
Next
For i = 0 To 49
Flag = False
For j = 0 To 48
If intA(j) > intA(j + 1) Then
Temp = intA(j)
intA(j) = intA(j + 1)
intA(j + 1) = Temp
Flag = True
End If
Next
If Flag = False Then Exit For
Next
MsgBox "最小值:" & intA(0) & ",最大值:" & intA(49) & ",平均值:" & s / 50 & "。"
End Sub
Dim intA(0 To 49) As Integer
Dim i As Integer
Dim j As Integer
Dim s As Integer
Dim Flag As Boolean
Dim Temp As Integer
Randomize
For i = 0 To 49
intA(i) = Int(100 * Rnd) + 1
s = s + intA(i)
Next
For i = 0 To 49
Flag = False
For j = 0 To 48
If intA(j) > intA(j + 1) Then
Temp = intA(j)
intA(j) = intA(j + 1)
intA(j + 1) = Temp
Flag = True
End If
Next
If Flag = False Then Exit For
Next
MsgBox "最小值:" & intA(0) & ",最大值:" & intA(49) & ",平均值:" & s / 50 & "。"
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询