vb语句 设计一个随机数程序,生成10个范围是1到100随机整数,并求出这10个数的最大值,最小值和平均数
2个回答
展开全部
'声明变量
dim Min_num as int
dim Max_num as int
dim Sum_num as int
dim Arr_num(9) as int
'赋予初始值
Min_num=101
Max_num=-1
Sum_num=0
'循环10次获得10个随机数
for i=1 to 10
randomize
Arr_num(i-1)=int(rnd*100)+1
'判断后赋值最小值
if Arr_num(i-1)<Min_num then Min_num=Arr_num(i-1)
'判断后赋值最大值
if Arr_num(i-1)>Max_num then Max_num=Arr_num(i-1)
'累计合计值,用于最后计算平均值
Sum_num=Sum_num+Arr_num(i-1)
next
msgbox ("最大值:" & cstr(Max_num) & vbcrlf & "最小值:" & cstr(Min_num) & vbcrlf & "平均数:" & cstr(cint(Sum_num)/10) & vbcrlf)
dim Min_num as int
dim Max_num as int
dim Sum_num as int
dim Arr_num(9) as int
'赋予初始值
Min_num=101
Max_num=-1
Sum_num=0
'循环10次获得10个随机数
for i=1 to 10
randomize
Arr_num(i-1)=int(rnd*100)+1
'判断后赋值最小值
if Arr_num(i-1)<Min_num then Min_num=Arr_num(i-1)
'判断后赋值最大值
if Arr_num(i-1)>Max_num then Max_num=Arr_num(i-1)
'累计合计值,用于最后计算平均值
Sum_num=Sum_num+Arr_num(i-1)
next
msgbox ("最大值:" & cstr(Max_num) & vbcrlf & "最小值:" & cstr(Min_num) & vbcrlf & "平均数:" & cstr(cint(Sum_num)/10) & vbcrlf)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询