Primality by trial division: Difference between revisions

Content added Content deleted
(Primality by trial division in Yabasic)
Line 1,975: Line 1,975:


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
<lang futurebasic>include "ConsoleWindow"
<lang futurebasic>window 1, @"Primality By Trial Division", (0,0,480,270)

def tab 6


local fn isPrime( n as long ) as Boolean
local fn isPrime( n as long ) as Boolean
dim as long i
long i
dim as Boolean result
Boolean result

if n < 2 then result = _false : exit fn
if n < 2 then result = NO : exit fn
if n = 2 then result = _true : exit fn
if n = 2 then result = YES : exit fn
if n mod 2 == 0 then result = _false : exit fn
if n mod 2 == 0 then result = NO : exit fn
result = _true
result = YES
for i = 3 to int( n^.5 ) step 2
if n mod i == 0 then result = _false : exit fn
for i = 3 to int( n^.5 ) step 2
if n mod i == 0 then result = NO : break
next i
next i
end fn = result
end fn = result


dim as long i, j
long i, j = 0


print "Prime numbers between 0 and 1000:"
print "Prime numbers between 0 and 1000:"
for i = 0 to 1000
for i = 0 to 1000
if ( fn isPrime(i) != _false )
if ( fn isPrime(i) != _false )
print i, : j++
printf @"%3d\t",i : j++
if j mod 10 == 0 then print
if j mod 10 == 0 then print
end if
end if
next</lang>
next

HandleEvents</lang>
Output:
Output:
Prime numbers between 0 and 1000:
Prime numbers between 0 and 1000:
2 3 5 7 11 13 17 19 23 29
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
179 181 191 193 197 199 211 223 227 229