梦想的边缘

总有梦想,总在追寻,却总在梦想的边缘徘徊,直到有一天,明白了,原来自己的梦想就在这不停追寻之中......

导航

实验11-6答案

Posted on 2005-06-17 19:19  梦想的边缘  阅读(477)  评论(0编辑  收藏  举报

程序界面:


代码:

'判断参数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