Vorige Pagina About the Author

' This is a conversion of my first program, written in 1979 in Basic

' Tested with Office 2007 under Windows 7

Sub Priem()

Sheets("Priem").Select

5   t2$ = "Prime Numbers "
    t1$ = t1$ + "Number of Prime Numbers ?"
    y0$ = InputBox(t1$, t2$, "10")
    N1 = Val(y0$)
    
    Cells(1, 1).Value = "This is a listing of " + Str$(N1) + " Prime numbers :"
            
    N = 0: V = 0
    k1 = 1: k2 = 1: n2 = 18
    
    For j1 = 1 To n2 - 1 Step 2
        Cells(2, j1).Value = "Nr"
        Cells(2, j1 + 1).Value = "Priem"
    Next j1
         
    For j1 = 1 To N1
160     V = V + 1
        Y = Int(V / 2 + 0.5)
        For X = 2 To Y
            Z = V / X
            W = Int(Z)
            If Z = W Then GoTo 160
        Next X
        N = N + 1
        Cells(1, 17).Value = N: Cells(1, 18).Value = V
        Cells(k1 + 3, k2).Value = N: Cells(k1 + 3, k2 + 1).Value = V
        k2 = k2 + 2: If k2 > n2 Then k2 = 1: k1 = k1 + 1
    Next j1
    
    Range(Cells(2, 1), Cells(k1, 18)).Select: Selection.Columns.AutoFit
    Range("A4").Select

End Sub

Vorige Pagina About the Author