急求VB编程“利用随机函数产生10个50-100之间的随机整数,求它们的最大值和平均值,要求用数组做”,谢谢

如题所述

Private Sub Command1_Click()
Randomize
Dim a(10) As Integer, imas as integer, imin as integer, Average as integer
imax = 49
imin = 101
Average=0
For i = 0 To 9
a(i) = Int(Rnd * 51) + 50
Average=Average+a(i)
If imax < a(i) Then imax = a(i)
If imin > a(i) Then imin = a(i)
Print a(i),
Next
Print
Print "最大值和最小值和平均值是:"; imax; imin; Average / 10
End Sub
楼上的平均值计算是错误的,并且循环多了一次
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-01-14
Private Sub Command1_Click()
Randomize
Dim a(10) As Integer
imax = 49
imin = 101
For i = 0 To 10
a(i) = Int(Rnd * 51) + 50
If imax < a(i) Then imax = a(i)
If imin > a(i) Then imin = a(i)
Print a(i),
Next
Print
Print "最大值和最小值和平均值是:"; imax; imin; (imax + imin) / 2
End Sub
第2个回答  2011-01-14
private sub command1_click()
Randomize
n=rnd()*10
for i=1 to n
S=S+i
a=a+1/S ''这里应该注意!!!!!
next
msgbox "n值为"+str(n)+",结果为"+str(a)
end sub
第3个回答  2011-01-14
你没给分啊!!吃白饭,不行咧
相似回答