Additive primes: Difference between revisions

Content added Content deleted
m (BASIC256 moved to the BASIC section.)
(Initial FutureBasic task solution added)
Line 1,749: Line 1,749:
54 values found.
54 values found.
</pre>
</pre>

=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">

local fn IsPrime( n as NSUInteger ) as BOOL
NSUInteger i
BOOL result = YES
if ( n < 2 ) then exit fn = NO
for i = 2 to n + 1
if ( i * i <= n ) and ( n mod i == 0 )
exit fn = NO
end if
next
end fn = result

local fn DigSum( n as NSUInteger ) as NSUInteger
NSUInteger s = 0
while ( n > 0 )
s += ( n mod 10 )
n /= 10
wend
end fn = s

void local fn AdditivePrimes( n as NSUInteger )
NSUInteger i, s = 0, counter = 0
printf @"Additive Primes:"
for i = 2 to n
if ( fn IsPrime(i) ) and ( fn IsPrime( fn DigSum(i) ) )
s++
printf @"%4ld \b", i : counter++
if counter == 10 then counter = 0 : print
end if
next
printf @"\n\nFound %lu additive primes less than %lu.", s, n
end fn

fn AdditivePrimes( 500 )

HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Additive Primes:
2 3 5 7 11 23 29 41 43 47
61 67 83 89 101 113 131 137 139 151
157 173 179 191 193 197 199 223 227 229
241 263 269 281 283 311 313 317 331 337
353 359 373 379 397 401 409 421 443 449
461 463 467 487

Found 54 additive primes less than 500.
</pre>



=={{header|Go}}==
=={{header|Go}}==