vb编程 找出100-900之间的无暇素数。所谓无暇素数是指本身为素数,且其
答案:2 悬赏:70 手机版
解决时间 2021-11-30 12:27
- 提问者网友:世勋超人
- 2021-11-29 17:54
vb编程 找出100-900之间的无暇素数。所谓无暇素数是指本身为素数,且其
最佳答案
- 五星知识达人网友:woshuo
- 2021-11-29 18:33
Private Sub Command1_Click()
Dim Inversion As Integer
For i = 100 To 900
Inversion = (i Mod 10) * 100 + (i 10 Mod 10) * 10 + i 100
If IsPrimeNumber(i) And IsPrimeNumber(Inversion) Then
k = k + 1
Print i;
If k Mod 10 = 0 Then Print
End If
Next i
Print
End Sub
Public Function IsPrimeNumber(ByVal n As Integer) As Boolean
IsPrimeNumber = True
For i = 2 To Sqr(n)
If n Mod i = 0 Then
IsPrimeNumber = False
Exit Function
End If
Next i
End Function
Dim Inversion As Integer
For i = 100 To 900
Inversion = (i Mod 10) * 100 + (i 10 Mod 10) * 10 + i 100
If IsPrimeNumber(i) And IsPrimeNumber(Inversion) Then
k = k + 1
Print i;
If k Mod 10 = 0 Then Print
End If
Next i
End Sub
Public Function IsPrimeNumber(ByVal n As Integer) As Boolean
IsPrimeNumber = True
For i = 2 To Sqr(n)
If n Mod i = 0 Then
IsPrimeNumber = False
Exit Function
End If
Next i
End Function
全部回答
- 1楼网友:神鬼未生
- 2021-11-29 19:30
我感觉这题目对新手来说是很难的,代码如下,运行效果见上图。
逐行手敲,亲测可用。
Private Sub Command1_Click()
Dim a, b, c, d As Integer
b = 2
For a = 100 To 900
c = 0
d = 0
For b = 2 To a - 1
If a Mod b = 0 Then
c = 1
End If
Next b
If c = 0 Then
y = a 100 + ((a 10) Mod 10) * 10 + (a Mod 10) * 100
For b = 2 To y - 1
If y Mod b = 0 Then
d = 1
End If
Next b
If d = 0 Then
Print "无暇素数为:" & a & " 倒序数为:" & y
End If
End If
Next a
End Sub
逐行手敲,亲测可用。
Private Sub Command1_Click()
Dim a, b, c, d As Integer
b = 2
For a = 100 To 900
c = 0
d = 0
For b = 2 To a - 1
If a Mod b = 0 Then
c = 1
End If
Next b
If c = 0 Then
y = a 100 + ((a 10) Mod 10) * 10 + (a Mod 10) * 100
For b = 2 To y - 1
If y Mod b = 0 Then
d = 1
End If
Next b
If d = 0 Then
Print "无暇素数为:" & a & " 倒序数为:" & y
End If
End If
Next a
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯