primes/primes.vb

32 lines
639 B
VB.net

' Visual Basic version of a Prime Number Finder
' haplo@mindstab.net
Imports System
Imports Math
Module Prime
Sub Main(ByVal CmdArgs() As String)
Dim cnt As Long, max As Long
Dim test As Double, isPrime As Byte, i as Long
If CmdArgs.Length < 1 then
Console.WriteLine("Usage: primesvb [Max Num]")
Return
Else
max = Convert.ToInt32(CmdArgs(0))
End If
For cnt = 3 to max Step +2
test = Math.Sqrt(cnt)
isPrime = 1
For i = 3 to test Step +2
If (cnt mod i) = 0 then
isPrime = 0
Exit For
End If
Next
If isPrime <> 0 Then
Console.WriteLine(cnt)
End If
Next
End Sub
End Module