VB程序设计 利用随即函数RND产生10个1到100的整数,输出这10个数,并输出它们中的最大值`最小值和平均值

利用随即函数RND产生10个1到100的整数,输出这10个数,并输出它们中的最大值`最小值和平均值 帮忙写出程序代码 谢谢

类似的题目做了不少!
哎!

Dim a(0 To 9) As Integer

Private Sub Command1_Click()
Dim min As Integer
Dim max As Integer
Dim av As Integer
Dim i As Integer
av = a(0)
min = a(0)
max = a(0)
Text1.Text = Text1.Text + "第 0 个数=" + CStr(a(0)) + vbCrLf
For i = 1 To 9
av = av + a(i)
Text1.Text = Text1.Text + "第 " + CStr(i) + " 个数=" + CStr(a(i)) + vbCrLf
If a(i) < min Then min = a(i)
If a(i) > max Then max = a(i)
Next i
av = av / 10
Text1.Text = Text1.Text + "最大数=" + CStr(max) + vbCrLf
Text1.Text = Text1.Text + "最小数=" + CStr(min) + vbCrLf
Text1.Text = Text1.Text + "平均数=" + CStr(av) + vbCrLf

End Sub

Private Sub Form_Load()
Dim i As Integer
Randomize
For i = 0 To 9
a(i) = CInt(100 * Rnd)
Next
End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-04-29
Private Sub Command1_Click()
Dim x(1 To 10) As Integer
xMax = 0
xMin = 100
Cls
Randomize
For i = 1 To 10
x(i) = 1 + 100 * Rnd()
If x(i) < xMin Then xMin = x(i)
If x(i) > xMax Then xMax = x(i)
Print x(i)
Next
Print "Max=" & xMax
Print "Min=" & xMin
End Sub

搞定

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

怎样用VB做随机产生10个1-100以内的整型数,求出其的最大值,最小值...
Print Print "最大值,最小值,平均数分别为:"; max; min; Cdbl(s) \/ 10 End Sub

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

vb编写程序,利用随机函数产生并显示10 个1~100 之间的随机整数并找出这...
Private Sub Command1_Click() Dim a(10) As Integer Randomize Max = 1 For i = 1 To 10 a(i) = 1 + Int(Rnd * 100) Print a(i); If a(i) > a(Max) Then Max = i Next i Print Print "a("; Max; ")="; a(Max)End Sub ...

利用VB制作一个“随机生成十个数字(1-100之间的整数)求极值(最大最小...
代码:Dim max, min As IntegerDim avg As DoublePrivate Sub Command1_Click()Dim num(10) As IntegerText1.Text = ""Label4.Caption = ""Label5.Caption = ""Label6.Caption = ""Dim i, j, temp, sum As Integersum = 0For i = 1 To 10num(i) = Int(Rnd * (100 + 1))sum...

vb 利用随机函数产生10个1~100之间的随机数,显示出最大值最小值,平均...
Private Sub Form_Click()Dim a(9) As Integer, max As Integer, min As Integer, arg As Single, i As IntegerRandomizeFor i = 0 To 9 a(i) = Int(Rnd * 100) + 1 arg = arg + a(i) If i = 0 Or a(i) > max Then max = a(i) If i = 0 Or a(i) ...

VB代码,计算机随机产生10个1—100的奇数,并由大到小输出
Private Sub Form_Load()Me.Show Dim a(10) As Integer Print "随机产生的10个1-100的奇数:"Randomize For i = 1 To 10 a(i) = Int(100 * Rnd + 1)If a(i) Mod 2 = 0 Then a(i) = a(i) + 1 Print a(i);Next Print Print "从大到小排列:"For i = 1 To 9 For ...

VB怎么写随机生成10个[1,100]之间的数,并从大到小排列的程序?
x = Rnd '第一个随机数总是2 Randomize Timer '找出随机数 'For i = 1 To 10 a(i) = Fix(1 + ((100 - 1 + 1) * Rnd)) '公式:Fix(m + (n-m+1 * Rnd))Randomize Timer Next i ''排序 For i = 1 To 10 - 1 For j = i + 1 To 10 If a(i) > a(j) Then...

vb程序:随机产生10个1-100之间(不包含1和100)的整数,并求出这10个数的...
Dim SUM As interger Dim i As intergerDim V As interger Private Sub Command1_Click() SUM = 0 For i = 1 To 10 Randomize V = int(1 + 98 * Rnd) SUM = SUM + V MsgBox "10个随机数的和为:" & SUM, 32 nextEnd Sub将楼上的改一下,应该更好 ...

vb考题:随机生成10个1~1000之间的整数,输出其中的最大数和最小数。
a(i) = Int(Rnd * 1000) + 1 Randomize Next For i = 0 To 9 Print a(i) & " ";Next Print Print "其中最大的数是:" & Max(a)Print "其中最小的数是:" & Min(a)End Sub Public Function Max(a() As Single) As Single Dim i As Integer, p As Single p = a(1)For ...

相似回答