VB题:定义一个长度为500的一维数组,为这个数组的每一个元素随机赋值一个整数值,

2024-11-15 11:27:20
推荐回答(1个)
回答1:

Private Sub Command1_Click()

  Randomize

  Dim a(500) As Integer

  For i = 1 To 500

    a(i) = Int(100 * Rnd)

    Print Format(a(i), "@@@");

    If i Mod 25 = 0 Then Print

  Next i

  Print

  For i = 1 To 499

    k = i

    For j = i + 1 To 500

      If a(j) < a(k) Then k = j

    Next j

    t = a(i): a(i) = a(k): a(k) = t

    Print Format(a(i), "@@@");

    If i Mod 25 = 0 Then Print

  Next i

  Print a(500)

End Sub