用VB编写一程序,产生20个0~100的随机数,并用子过程的方法按从大到小的顺序排列显示

如题所述

'试一下:
PrivateSubCommand1_Click()
Dimarr(1To20),i
Fori=1To20
Randomize
arr(i)=Int(Rnd*101)
Next
fcarr
PrintJoin(arr,vbNewLine)'自己修改,我是直接打印的可以分开
EndSub
Functionfc(arr)
Dimi,j,t
Fori=LBound(arr)ToUBound(arr)-1
Forj=i+1ToUBound(arr)
IfVal(arr(i))t=arr(i):arr(i)=arr(j):arr(j)=t
EndIf
Next
Next
EndFunction
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-12-12
用冒泡排序方法:
Option Explicit
Option Base 1
Dim a(10) As Integer
Dim i As Integer
Dim n As Integer
Private Sub Command1_Click()
n = n + 1
If n >= 9 Then
Cls
n = 0
End If

For i = 1 To 10
a(i) = Int(Rnd * 100)

Print a(i);
Next i
Print
End Sub
Private Sub Command2_Click()
Dim j, l, t, s As Integer
n = n + 1
If n >= 9 Then
Cls
n = 0
End If
For i = 1 To 9
For j = i + 1 To 10
If a(j) < a(i) Then
t = a(j)
s = a(i)
a(i) = t
a(j) = s

End If
Next j
Next i
For l = 1 To 10
Print a(l);
Next l
Print
Print "---------------------------------------"
End Sub

用VB编写一程序,产生20个0~100的随机数,并用子过程的方法按从大到小的...
PrivateSubCommand1_Click()Dimarr(1To20),i Fori=1To20 Randomize arr(i)=Int(Rnd*101)Next fcarr PrintJoin(arr,vbNewLine)'自己修改,我是直接打印的可以分开 EndSub Functionfc(arr)Dimi,j,t Fori=LBound(arr)ToUBound(arr)-1 Forj=i+1ToUBound(arr)IfVal(arr(i))t=arr(i):arr(...

vb编程产生20个200以内的随机数并从大到小排序输出
Private Sub Command1_Click()Dim a(20) As Integer Print "产生的数:"For i = 1 To 20 a(i) = Int(Rnd * 201)Print a(i);Next i Print For i = 1 To 19 For j = 1 To 20 - i If a(j) < a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = ...

VB随机生成20个1-100之间的随机数,点一下按钮打印一个,共点20次打印...
Integer, min As Integer, maxp As Integer, minp As IntegerFor i = 1 To 20A(i) = Int(100 * Rnd) + 1st = st & Str(A(i))If i Mod 10 = 0 Then st = st & vbCrLfNext iText1 = stj = 0End SubPrivate Sub Command2_Click()j = j + 1If j > 20 Then j = 1...

用vb做 利用随机函数产生20 个50~100范围内的随机整数,显示它们的最...
savg = 0 Print "50-100范围内的20个随机数如下:"For i = 1 To 20 num(i) = 50 + Int(51 * Rnd) '产生[50,100]区间的20个随机数 If i = 1 Then smax = num(i): smin = num(i)If smax < num(i) Then smax = num(i) '求最大值 If smin > num(i) Then smin =...

在vb中怎样产生20个0到100的随机数并统计里面大于90的个数
Private Sub Command1_Click()Randomize Dim x As Integer For i = 1 To 20 x = Rnd * 101 Print x;If i Mod 10 = 0 Then Print If x > 90 Then big = big + 1 Next i Print Print "大于90的数的个数:"; big Print End Sub ...

VB方面的:利用随机函数产生20个50--100范围内的随机数,显示它们的最大...
Private Sub Form_click()Dim n(1 To 20) As Integer Dim i, j, ave, temp Randomize For i = 1 To 20 n(i) = Int((51 * Rnd) + 50)Print n(i)Next i For j = 1 To 19 For i = j + 1 To 20 If n(i) >= n(j) Then temp = n(i)n(i) = n(j)n(j) = ...

产生0~100的随机数 vb
rnd*(上界–下界+1)+下界 如果要求产生的随机数要求包含上界(本题中的100),是正确的。rnd*(上界–下界)+下界 如果要求产生的随机数要求不包含上界(本题中的100),或没有明确说明是否包含上界(本题中的100),就应该没有+1。

vb程序随机1到100产生二十个随机数,并从高到低排序
Dim score(1 To 20) As Integer, i As Integer, j As Integer For i = 1 To 20 '用随机函数给数组score()赋100以内的值 score(i) = Int(Rnd * 100)Next i For i = 20 To 2 Step -1 '用冒泡排序法对已赋值的数组进行排序 For j = 1 To i - 1 If score(j) > sco...

vb程序设计题 求代码 随机产生20个0~100的正整数(包括0和100),存放...
If i = 10 Then Print End IfNext iAve = sum \/ 20Mx = Max(arr)Mn = Min(arr)For i = 1 To 20If arr(i) = Mx Thena = iEnd IfIf arr(i) = Mn Thenb = iEnd IfNext iPrint: PrintPrint "平均值为:" & AvePrint "最大值为:" & Mx & " 对应数组下标为:" & a...

vb中产生20个1-100的随机数,挑选其中的素数
Dim a(19) As IntegerPrivate Sub Command1_Click()Print "产生20个随机数为:"Dim i As IntegerFor i = 0 To 19 a(i) = 1 + Int(Rnd * 100) Print a(i); If (i + 1) Mod 5 = 0 Then PrintNextEnd SubPrivate Sub Command2_Click()Print "其中素数为:"Dim i As Integer,...

相似回答