求高手帮忙写个vb程序!急!急!急!

2024-11-22 19:13:14
推荐回答(2个)
回答1:

Function IsPrime(Num As Long) As Boolean
If Num < 2 Then IsPrime = False: Exit Function

Dim i As Long

For i = 2 To Sqr(Num)
If (Num Mod i) = 0 Then
IsPrime = False
Exit Function
End If
Next i

IsPrime = True
End Function

Private Sub Command1_Click()
Dim a As Long
Dim b As Long
Dim i As Long

a = 100
b = 500
For i = a To b
If IsPrime(i) And IsPrime(CLng(StrReverse(CStr(i)))) Then
Print i
End If
Next i

End Sub

回答2:

Private Sub Command1_Click()
Dim a As Integer, b As Integer, i As Integer

a = 10
b = 10000

For i = a To b
If IsSuShu(i) Then
If IsSuShu(Val(StrReverse(CStr(i)))) Then Print i
End If
Next
End Sub

Private Function IsSuShu(ByVal iNum As Integer) As Boolean
Dim i As Integer

For i = 2 To Sqr(iNum)
If iNum Mod i = 0 Then Exit Function
Next
IsSuShu = True
End Function