Piprimes: Difference between revisions

47 bytes added ,  10 months ago
m
Line 479:
<syntaxhighlight futurebasic"j">
local fn IsPrime( n as NSUInteger ) as BOOL
BOOL isPrime = YES
NSUInteger i
 
if n < 2 then exit fn = NO
if n = 2 then exit fn = YES
if n mod 2 == 0 then exit fn = NO
for i = 3 to int(n^.5) step 2
if n mod i == 0 then exit fn = NO
next
end fn = isPrime
 
 
local fn Piprimes( limit as NSUInteger )
NSUInteger n = 0, p = 1
 
printf @"Piprimes from 1 through %lu:\n", limit
while ( n < limit )
printf @"%2lu \b", n
if p mod 10 == 0 then print
p++
if ( fn IsPrime(p) ) then n++
wend
end fn
 
715

edits