vb题目:产生20个1-100的随机数,挑选出其中的质数,求代码答案

2024-11-06 02:42:52
推荐回答(1个)
回答1:

Private Sub Command1_Click()

  Print "======="

  Dim a(20) As Integer

  For i = 1 To 20

    a(i) = Rnd * 20 + 1

    Print a(i);

    If i Mod 10 = 0 Then Print

  Next i

  Print

  Print "其中是质数的有:";

  For i = 1 To 20

    If ss(a(i)) Then Print a(i);

  Next i

  Print: Print

End Sub


Function ss(x As Integer) As Boolean

  ss = False

  For i = 2 To Sqr(x)

    If x Mod i = 0 Then Exit Function

  Next i

  ss = True

End Function