vb6.0 求素数按奇偶显示

前端之家收集整理的这篇文章主要介绍了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

猜你在找的VB相关文章