vb6.0 求素数按奇偶显示

 

Private Sub Command1_Click()
Me.Refresh
Dim x As Integer
    For x = 2 To 100
        If x Mod 2 = 0 Then
            If prime(x) = 1 Then
                Print x & "  这是偶数"
            End If
        Else
            If prime(x) = 1 Then
                Print x & "  这是奇数"
            End If
        End If
    Next x

End Sub
Function prime(x As Integer) As Integer
Dim i As Integer
    For i = 2 To x - 1
       If x Mod i = 0 Then
           Exit For
       End If
    Next i
    If i >= x Then
        prime = 1
    Else:
       prime = 0
    End If
End Function

vb6.0 求素数按奇偶显示_第1张图片

你可能感兴趣的:(vb6.0 求素数按奇偶显示)