回覆列表
  • 1 # 熱心市民小劉

    Private Function check(i As Integer) As Boolean

    For j = 2 To CInt(Sqr(i)) + 1 "從2迴圈到i的平方根

    If i Mod j = 0 Then "如果i除以j的餘數為0,說明i不是素數

    check = False "返回false

    Exit Function "退出本過程

    End If

    Next j

    check = True "迴圈結束沒有退出過程,說明i不能整除從2到i平方根的所有數,也就是說i是素數,返回true

    End Function

    Private Sub Command1_Click()

    Dim k As Integer, n As Integer

    For k = 1 To 100

    If n Mod 5 = 0 Then Print

    If check(k) Then

    Print k;

    n = n + 1

    End If

    Next

    End Sub

  • 中秋節和大豐收的關聯?
  • 南瓜紫薯餅的做法寶寶輔食?