判断一个数是否是素数

来源:互联网 发布:昆明询知培训中心 编辑:程序博客网 时间:2024/05/17 21:51

'Label1.Caption = IIf(IsPrimer(Int(Val(Text2.Text))) = 0, "bushi", "shi")

 End Sub

Private Function IsPrimer(n As Integer) As Integer

 

 Dim i As Integer

  For i = 2 To n - 1

      If n Mod i = 0 Then

       Exit For

      End If

   Next i

    If i = n Then

       IsPrimer = n

   Else

       IsPrimer = 0

   End If

   

End Function

 

 

原创粉丝点击