private sub command1_click()
dim i,j,n
n=val(inputbox("n="))
if IsPrime(n) then
print n & "是素数."
else
for i=n+1 to n+100
if IsPrime(i) then print "大于" & n & "的最小素数是:" & i : Exit For
next
end if
end sub
Function IsPrime(ByVal n As Long) As Boolean
Dim i As Long
if n<2 then
IsPrime = False
else
IsPrime = True
For i = 2 To sqr(n)
If n Mod i = 0 Then IsPrime = False: Exit For
Next
end if
End Function
Private Sub command1_click()
Dim a As Long, b As Long, n As Long
n = InputBox("请输入一个整数 N ")
If sushupd(n) Then
Print n & " 是素数 "
Else
i = n + 1
Do While Not sushupd(i)
i = i + 1
Loop
Print "大于 " & n & " 的最小素数是:" & i
End If
End Sub
Function sushupd(ByVal n As Long) As Boolean
Dim i As Long
If n < 2 Then
sushupd = False
Else
sushupd = True
i = 2
Do While i <= Sqr(n) And sushupd
If n Mod i = 0 Then sushupd = False
i = i + 1
Loop
End If
End Function
123