17 lines
491 B
Text
17 lines
491 B
Text
print "Rosetta Code - Primality by trial division"
|
|
print
|
|
[start]
|
|
input "Enter an integer: "; x
|
|
if x=0 then print "Program complete.": end
|
|
if isPrime(x) then print x; " is prime" else print x; " is not prime"
|
|
goto [start]
|
|
|
|
function isPrime(p)
|
|
p=int(abs(p))
|
|
if p=2 then isPrime=1: exit function 'prime
|
|
if p=0 or p=1 or (p mod 2)=0 then exit function 'not prime
|
|
for i=3 to sqr(p) step 2
|
|
if (p mod i)=0 then exit function 'not prime
|
|
next i
|
|
isPrime=1
|
|
end function
|