急!!!大学生程序语言设计(VB)题目,如下,求高手解答!明天考试了!

2024-11-07 03:11:36
推荐回答(2个)
回答(1):

Randomize
Dim min As Integer: min = 101
Dim max As Integer
Dim sum As Integer
Dim a(20) As Integer
For i = 0 To 19
a(i) = 50 + Int(Rnd * 51)
If a(i) > max Then max = a(i)
If a(i) < min Then min = a(i)
sum = sum + a(i)
Next
MsgBox "最大值:" & max & vbCrLf & "最小值:" & min & vbCrLf & "平均值:" & sum / 20

回答(2):

Randomize(Timer)
Dim a(1 to 20) as Integer
Dim intC as Integer
For i=1 to 20
intC=CInt(Rnd()*(101-50)+50)
a(i)=intC
Next
然后用冒泡法求最大值、最小值。
平均值应该不用说了吧?
有什么问题欢迎随时交流。