vb问题 高手请进随机产生50个整数(范围20..50),求之中能被3整除的最小数并与数组中的第一个元素交换位置,输出交

1个回答

  • Private Sub Form_Click()

    Me.AutoRedraw = True

    Dim a(1 To 50) As Integer

    Dim minD As Integer

    Dim tmpD As Integer

    Dim j As Integer

    minD = 51

    Dim i As Long

    For i = 1 To 50

    Randomize

    a(i) = Int(Rnd * 31 + 20)

    If a(i) Mod 3 = 0 Then

    If minD > a(i) Then minD = a(i): j = i

    End If

    Next

    tmpD = a(1)

    a(1) = a(j)

    a(j) = tmpD

    j = 0

    For i = 1 To 50

    If j Mod 10 = 0 Then Print

    Print a(i);

    j = j + 1

    Next

    Print

    Print "最小数:" & minD

    End Su