23 lines
482 B
Text
23 lines
482 B
Text
' FB 1.05.0 Win64
|
|
|
|
Function isPrime(n As Integer) As Boolean
|
|
If n < 2 Then Return False
|
|
If n = 2 Then Return True
|
|
If n Mod 2 = 0 Then Return False
|
|
Dim limit As Integer = Sqr(n)
|
|
For i As Integer = 3 To limit Step 2
|
|
If n Mod i = 0 Then Return False
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
' To test this works, print all primes under 100
|
|
For i As Integer = 1 To 99
|
|
If isPrime(i) Then
|
|
Print Str(i); " ";
|
|
End If
|
|
Next
|
|
|
|
Print : Print
|
|
Print "Press any key to quit"
|
|
Sleep
|