Primality by trial division: Difference between revisions

m
(Primality by trial division in Yabasic)
Line 1,975:
 
=={{header|FutureBasic}}==
<lang futurebasic>includewindow 1, @"ConsoleWindowPrimality By Trial Division", (0,0,480,270)
 
def tab 6
 
local fn isPrime( n as long ) as Boolean
dim as long i
dim as Boolean result
 
if n < 2 then result = _falseNO : exit fn
if n = 2 then result = _true YES : exit fn
if n mod 2 == 0 then result = _falseNO : exit fn
result = _trueYES
for i = 3 to int( n^.5 ) step 2
if n modfor i == 03 thento resultint( = _falsen^.5 :) exitstep fn2
if n mod i == 0 then result = NO : break
next i
end fn = result
 
dim as long i, j = 0
 
print "Prime numbers between 0 and 1000:"
for i = 0 to 1000
if ( fn isPrime(i) != _false )
printprintf i@"%3d\t",i : j++
if j mod 10 == 0 then print
end if
next</lang>
 
HandleEvents</lang>
Output:
Prime numbers between 0 and 1000:
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
416

edits