vb语句 设计一个随机数程序,生成10个范围是1到100随机整数,并求出这10个数的最大值,最小值和平均数

如题所述

'声明变量
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)
温馨提示:内容为网友见解,仅供参考
第1个回答  2014-04-02
好的话 给采纳不?

vb语句 设计一个随机数程序,生成10个范围是1到100随机整数,并求出这...
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)'累计合计值,用于...

利用VB如何设计下面问题:利用随机数产生10个1~100之间的随机数,显示...
Next q avg1 = sum \/ UBound(n())Print "10个数中奇数之平均数为" & avg1 End Sub

利用VB制作一个“随机生成十个数字(1-100之间的整数)求极值(最大最小...
Caption = minLabel6.Caption = avgEnd IfEnd Sub设计好的窗体:程序运行的窗体:

vb 利用随机函数产生10个1~100之间的随机数,显示出最大值最小值,平均...
NextPrintPrint "最大值:"; maxPrint "最小值:"; minPrint "平均值:"; arg \/ 10End Sub

VB怎么写随机生成10个[1,100]之间的数,并从大到小排列的程序?
Do While abc = 1 abc = 1 For i = 1 To 10 - 1 For j = i + 1 To 10 If a(i) > a(j) Then a(j) = Fix(1 + ((100 - 1 + 1) * Rnd))Randomize Timer abc = 0 End If Next j Next i Loop 'For i = 1 To 10 MsgBox a(i)Next i End 参考资料:原创 ...

vb题 输出任意10个数字中最大的数
Dim Min, Max, D As Double Dim Str As String Dim N As Integer For N = 1 To 10 Str = InputBox("请输入第" & N & "个数", "输入") '循环输入10个数字 D = Val(Str)Print D '初始化最大值和最小值均为输入的第一个数 If N = 1 Then Max = D: Min = D '如果输入...

如何用VB的for循环编写产生10个100~200直接的数,求最大值
使用VB语言编写的程序,实现产生10个100~200的随机数,并求它们的最大值:```Dim num(9) As Integer '定义数组存储随机数Dim maxNum As Integer '定义变量存储最大值Randomize '初始化随机数种子For i = 0 To 9 '循环产生10个随机数num(i) = Int((200 - 100 + 1) * Rnd + 100) '...

VB 作业 随机产生10个小于100的数 并求出其中最大的值
Cls '清屏 Randomize '初始化随机数生成器。Dim a(1 To 10)For x = 1 To 10 '产生10个循环 a(x) = Int(100 * Rnd()) '产生小于100的随机整数 Next Dim i, j, t As Integer For i = 1 To 10 For j = i + 1 To 10 If a(i) > a(j) Then '将较大的数推到最后 t ...

vb编程:随机产生10个两位随机奇数,求其中的最大值、最小值和平均值
Private Sub Form_Load()Dim a(10) As Single Dim i, j As Single For i = 0 To 9 '产生10个随机数 j = 0 Do Until j < 100 And j Mod 2 = 1 Randomize j = Int(Rnd * 100) + 10 Loop a(i) = j Next i Label1.Caption = "这10个数为:"For i = 0 To 9 Labe...

VB产生10个[1,100]的随机数
Text1 = "最大" & Max Text2 = "最新" & Min Text3="和"& t Text4 = "平均" & Round(e, 6)End Sub Private Sub Form_Load()Dim fo As Long Randomize Timer For fo = 1 To 10 Label1 = Label1 & Rand(1, 100) & vbCrLf Next Label1.Height = TextHeight("") * 10 End...

相似回答