vb题目:打印输出1000以内所有的质数 求代码答案

2024-12-21 06:15:48
推荐回答(1个)
回答1:

Private Sub Command1_Click()

  Dim i As Integer

  For i = 1 To 1000

    If ss(i) Then

      Print i;

      k = k + 1

      If k Mod 10 = 0 Then Print

    End If

  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 = x > 1

End Function