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 n 0
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 m n Then
List1.AddItem "(" & m & "," & n & ")"
End If
Next m
End Sub
Private Sub Command2_Click()
List1.Clear
End Sub
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
热门考点