vb利用随机函数产生20歌50-100之间的随机整数,显示它们的最大值,最小值和平均值

2024-11-12 17:01:46
推荐回答(1个)
回答1:

sub 随州蠢机整数()
dim i as byte ,j as byte , max as byte,min as byte , ave as single
dim a(1 to 20) as integer
for i=1 to 20
a(i)=Int(51 * Rnd + 50)
next
max=a(1)
min=a(1)
ave=0
for j=1 to 20
if a(i)> max then
max=a(i)
end if
if a(i) min=a(i)
end if
ave=ave+a(i)
next j
ave=round(ave/20,2)
print "最大的数是:" & max & chr(13) & "最小的数是世此:" & min & chr(13) _ & "平均值是:册返陪" & ave
end sub