Private Function Prime(n As Integer) As Boolean
Dim k As Integer, Yes As Boolean
Yes=True
For k= 2 to Int(Sqr(n))
IF n mod k=0 Then Yes=False:Exit For
Next K
Prime=Yes
End Function
private sub form_click()
Dim N As Integer
N=Val(InputBox("输入一个正整数 N=?"))
if prime(N)=True Then
print N ;"是素数"
Else
print N;"不是素数"
End IF
End Sub
Private Sub Command1_Click()
Dim x As Integer
x = Val(InputBox("请输入一个数以判断是否是素数"))
Prime (x)
End Sub
Private Function Prime(m As Integer)
Dim n As Integer
Dim i As Integer
n = Int(Sqr(m)) + 1
For i = 2 To n
If m Mod i = 0 Then
Exit For
End If
Next i
If i = n + 1 Then
Print m & "是素数"
Else
Print m & "不是素数"
End If
End Function