在窗体上放一个按钮,双击按钮,删掉所有代码,粘贴以下代码:
Private Sub Command1_Click()
Dim j As Integer
For j = 1 To 1000
If StrReverse(j) = j And sushu(j) = True Then
Print j
End If
Next j
End Sub
Private Function sushu(ByVal n As Long) As Boolean
Dim i As Long
For i = 2 To n - 1
If (n Mod i) = 0 Then Exit For
Next i
If i = n Then sushu = True
End Function
按F5运行,点按钮,完成
首先2,4位没1位又不算所以只要搜索3位就可以了
begin
for i:=100 to 999 do
if (i mod 10)=(i div 100) then {判断回文数}
begin {判断素数}
j:=3;
repeat
t:=1;
if (i mod j)=0 then t:=0;
j:=j+1;
until((t=0)or(j>sqrt(i)));
if t=1 then writeln(i);
end;
end.