vb6.0 500以后100个素数和的求法 求代码

2025-01-31 06:43:31
推荐回答(1个)
回答1:

Private Sub Command1_Click()

    Dim a As Integer, n As Integer, i As Integer, x As Integer, s As Long

    a = 500

    n = 0

    s = 0

    Do While n < 100

        a = a + 1

        x = 0

        For i = 2 To a - 1

            If a Mod i = 0 Then

                x = x + 1

                Exit For

            End If

        Next

        If x = 0 Then

            n = n + 1

            Print a;

            s = s + a

            If n Mod 10 = 0 Then

                Print

            End If

        End If

    Loop

    Print

    Print "500以后100个素数的和=", s

End Sub