判断一个数是否是素数

来源:互联网 发布:js数字和字符串计算 编辑:程序博客网 时间:2024/05/17 23:24

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

  

End Sub

 

 

Private Function IsPrimer(n As Integer) AsInteger

 

   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

 

 

 

 

 

 

 

 

 

 

原创粉丝点击