程序界面:
代码:
'判断参数a是否为素数,若是素数,返回True;否则返回False
Private Function SuShu(a As Integer) As Boolean
Dim i As Integer
For i = 2 To a - 1
If a Mod i = 0 Then Exit For
Next i
If i = a Then
SuShu = True
Else
SuShu = False
End If
End Function
Private Sub Command1_Click()
Dim j As Integer
For j = 2 To 100 - 2
If SuShu(j) = True And SuShu(j + 2) = True Then
List1.AddItem "(" & j & "," & j + 2 & ")"
End If
Next j
End Sub