How to resolve the algorithm Descending primes step by step in the FutureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Descending primes step by step in the FutureBasic programming language
Table of Contents
Problem Statement
Generate and show all primes with strictly descending decimal digits.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Descending primes step by step in the FutureBasic programming language
Source code in the futurebasic programming language
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
void local fn DesecendingPrimes( limit as long )
long i, n, mask, num, count = 0
for i = 0 to limit -1
n = 0 : mask = i : num = 9
while ( mask )
if mask & 1 then n = n * 10 + num
mask = mask >> 1
num--
wend
mda(i) = n
next
mda_sort @"compare:"
for i = 1 to mda_count (0) - 1
n = mda_integer(i)
if ( fn IsPrime( n ) )
printf @"%10ld\b", n
count++
if count mod 10 == 0 then print
end if
next
printf @"\n\n\tThere are %ld descending primes.", count
end fn
window 1, @"Desecending Primes", ( 0, 0, 780, 230 )
print
CFTimeInterval t
t = fn CACurrentMediaTime
fn DesecendingPrimes( 512 )
printf @"\n\tCompute time: %.3f ms\n",(fn CACurrentMediaTime-t)*1000
HandleEvents
You may also check:How to resolve the algorithm Sleep step by step in the TXR programming language
You may also check:How to resolve the algorithm 100 doors step by step in the GW-BASIC programming language
You may also check:How to resolve the algorithm IBAN step by step in the Lobster programming language
You may also check:How to resolve the algorithm Rosetta Code/Rank languages by popularity step by step in the jq programming language
You may also check:How to resolve the algorithm Formatted numeric output step by step in the SQL programming language