编写VB过程,判断1个数是否是素数,如果是素数返回True,否则返回False。

2024-11-15 00:17:29
推荐回答(1个)
回答1:

Private Function IsPrime(Num As Integer) As Boolean
Dim tmp As Boolean
Dim i As Integer
tmp = True
For i = 2 To Sqr(Num)
If Num Mod i Then
Else
tmp = False
Exit For
End If
Next
IsPrime = tmp
End Function