Factorial primes: Difference between revisions

Content added Content deleted
(Factorial primes in FreeBASIC)
(Factorial primes in various dialects BASIC (BASIC256, Run BASIC, and Yabasic))
Line 111: Line 111:
9: 12! - 1 = 479001599
9: 12! - 1 = 479001599
10: 14! - 1 = 87178291199</pre>
10: 14! - 1 = 87178291199</pre>

=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic">include "isprime.kbs"
include "factorial.kbs"

print "First 10 factorial primes:"
found = 0
i = 1
while found < 9
fct = factorial (i)

if isprime(fct-1) then
found += 1
print rjust(string(found),2); ": "; rjust(string(i),2); "! - 1 = "; fct-1
end if
if isprime(fct+1) then
found += 1
print rjust(string(found),2); ": "; rjust(string(i),2); "! + 1 = "; fct+1
end if
i += 1
end while
end</syntaxhighlight>

==={{header|Run BASIC}}===
<syntaxhighlight lang="vb">function isPrime(n)
if n < 2 then isPrime = 0 : goto [exit]
if n = 2 then isPrime = 1 : goto [exit]
if n mod 2 = 0 then isPrime = 0 : goto [exit]
isPrime = 1
for i = 3 to int(n^.5) step 2
if n mod i = 0 then isPrime = 0 : goto [exit]
next i
[exit]
end function

function factorial(n)
factorial = 1
if n > 1 then factorial = n * factorial(n -1)
end function

print "First 10 factorial primes:"
found = 0
i = 1
while found < 10
fct = factorial(i)

if isPrime(fct-1) then
found = found + 1
print using("##", found); ": "; using("##", i); "! - 1 = "; fct-1
end if
if isPrime(fct+1) then
found = found + 1
print using("##", found); ": "; using("##", i); "! + 1 = "; fct+1
end if
i = i + 1
wend</syntaxhighlight>

==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic">import isprime
import factorial

print "First 10 factorial primes:"
found = 0
i = 1
while found < 10
fct = factorial (i)
if isPrime(fct-1) then
found = found + 1
print found using("##"), ": ", i using("##"), "! - 1 = ", fct-1
fi
if isPrime(fct+1) then
found = found + 1
print found using("##"), ": ", i using("##"), "! + 1 = ", fct+1
fi
i = i + 1
end while</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==