vbvbvbvbvb定义一个判断素数的函数过程,调用该函数过程求出所有的绝对素数
问题描述:
vbvbvbvbvb定义一个判断素数的函数过程,调用该函数过程求出所有的绝对素数
答
Private Function prime(ByVal n As Long) As Integer
Dim k As Integer
prime = False
For k = 2 To Int(Sqr(n))
If n Mod k = 0 Then Exit Function
Next k
prime = True
End Function
Private Function nx(ByVal n As Long) As Long
Dim p As Integer, s As String
Do While n0
p = n Mod 10
n = n \ 10
s = s & p
Loop
nx = Val(s)
End Function
Private Sub Command1_Click()
Dim m As Long, n As Long, i As Long
For m = 1 To 100 Step 2
n = nx(m)
If prime(m) And prime(n) And mn Then
List1.AddItem "(" & m & "," & n & ")"
End If
Next m
End Sub
Private Sub Command2_Click()
List1.Clear
End Sub