如何用vb解答随机产生N个二位正整数存放在一维数组中,求数组的最大值、平均值。

各位高手帮帮忙

Private Sub Form_Click()
Dim N as Integer,A() as Integer
Dim Max as integer,Min as integer,Avg as Integer
N=10
Redim A(1 to n) as Integer
Randomize
Max=0
Min=100
For i=1 to N
A(i)=Int(Rnd*90)+10
if A(i)>Max Then Max=a(i)
If A(i)<Min Then Min=A(i)
Avg=Avg+A(i)
Next
Print "最大值为:" & Max
Print "最小值为:" & Min
Print "平均值为:" & Avg/N
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-05-24
dim N as integer,i as integer,A() as integer,S as integer,Max as integer
N=inputbox("请输入N的值:")
redim A(N)
S=0
Max=0
for i=1 to n
randomize
a(i)=int(rnd()*90+10)
s=s+a(i)
if max<a(i) then max=a(i)
next i
print "数组的最大值是:";max
print "数组的平均值是:";s/n
第2个回答  2008-05-24
Private Sub Form_Click()
Dim n As Integer
Dim a() As Integer
Dim max As Integer
Dim sum As Double
n = InputBox("请输入n的值", "输入框")
For i = 1 To n
Randomize
ReDim Preserve a(1 To n)
a(i) = Int(Rnd * 99) + 10
List1.AddItem a(i)
sum = sum + a(i)
Next
For j = 1 To n - 1
max = IIf(a(j) > a(j + 1), a(j), a(j + 1))
Next
Debug.Print "最大值是:" & max
Debug.Print "平均值是:" & sum / n
End Sub