窗体上有1个文本框Text,4个命令按钮分别为Command1(“产生随机数”) 10
窗体上有1个文本框Text,4个命令按钮分别为Command1(“产生随机数”)Command2(“最小值”)Command3(”最大值“)Command4(”平均值“)...
窗体上有1个文本框Text,4个命令按钮分别为Command1(“产生随机数”)Command2(“最小值”)Command3(”最大值“)Command4(”平均值“),要求:
(1)单击”Command1”时,在文本框中显示10个随机整数,逗号分隔
(2)单机“Command2”时,通过消息框(MsgBox)显示10个数中的最小值
(3)单击“Command3”时,通过消息框显示10个数中的最大值
(4)单机Command4时,通过消息框显示10个数的平均值 展开
(1)单击”Command1”时,在文本框中显示10个随机整数,逗号分隔
(2)单机“Command2”时,通过消息框(MsgBox)显示10个数中的最小值
(3)单击“Command3”时,通过消息框显示10个数中的最大值
(4)单机Command4时,通过消息框显示10个数的平均值 展开
2个回答
展开全部
Dim n(9) As Variant, max As Integer, min As Integer, sum As Integer
Private Sub Command1_Click()
Dim i As Integer
Randomize
For i = 0 To 9
n(i) = Int(Rnd * 90) + 10
If i = 0 Then
max = n(i)
min = n(i)
Else
If max < n(i) Then max = n(i)
If min > n(i) Then min = n(i)
End If
sum = sum + n(i)
Next
Text1.Text = Join(n, ",")
End Sub
Private Sub Command2_Click()
MsgBox "最小值是" & min
End Sub
Private Sub Command3_Click()
MsgBox "最大值是" & max
End Sub
Private Sub Command4_Click()
MsgBox "平均值是" & sum / 10
End Sub
Private Sub Command1_Click()
Dim i As Integer
Randomize
For i = 0 To 9
n(i) = Int(Rnd * 90) + 10
If i = 0 Then
max = n(i)
min = n(i)
Else
If max < n(i) Then max = n(i)
If min > n(i) Then min = n(i)
End If
sum = sum + n(i)
Next
Text1.Text = Join(n, ",")
End Sub
Private Sub Command2_Click()
MsgBox "最小值是" & min
End Sub
Private Sub Command3_Click()
MsgBox "最大值是" & max
End Sub
Private Sub Command4_Click()
MsgBox "平均值是" & sum / 10
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询