vb编程产生20个200以内的随机数并从大到小排序输出

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) = t

      End If

    Next j

  Next i

  Print "排序以后:"

  For i = 1 To 20

    Print a(i);

  Next i

  Print

End Sub

温馨提示:内容为网友见解,仅供参考
第1个回答  2016-01-05
dim i as integer,A[19] as double,dbl_Tmp as double,j as integer,k as integer
for i=0 to 19
dbl_Tmp=rnd(0)*200 '产生随机数
for j=0 to 19 ‘遍历数组
if dbl_Tmp >A[j] then ’找到位置
for k=19 to j+1 step -1 '插入新产生的随机数
A[k]=A[k-1]
next k
A[j]=dbl_tmp
Exit for
Endif
next j
next i
相似回答