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> |
<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 |
||
long i |
|||
Boolean result |
|||
if n < 2 then result = |
if n < 2 then result = NO : exit fn |
||
if n = 2 then result = |
if n = 2 then result = YES : exit fn |
||
if n mod 2 == 0 then result = |
if n mod 2 == 0 then result = NO : exit fn |
||
result = |
result = YES |
||
for i = 3 to int( n^.5 ) step 2 |
|||
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 |
||
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 ) |
||
printf @"%3d\t",i : j++ |
|||
if j mod 10 == 0 then print |
if j mod 10 == 0 then print |
||
end if |
end if |
||
next |
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 |
|||
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 |
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 |