Factorial primes: Difference between revisions

m
FreeBASIC moved to the BASIC section.
(Factorial primes in Gambas)
m (FreeBASIC moved to the BASIC section.)
Line 136:
end</syntaxhighlight>
 
==={{header|Run BASICFreeBASIC}}===
<syntaxhighlight lang="vb">function#include isPrime(n)"isprime.bas"
#include "factorial.bas"
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
 
functionPrint "First 10 factorial(n) primes:"
Dim As Integer found = 0, i = 1
factorial = 1
While found < 10
if n > 1 then factorial = n * factorial(n -1)
Dim As Integer fct = factorial (i)
end function
 
If isprime(fct-1) Then
print "First 10 factorial primes:"
found += 01
Print Using "##: ##_! - 1 = &"; found; i; fct-1
i = 1
End If
while found < 10
If isprime(fct+1) Then
fct = factorial(i)
found += 1
 
Print Using "##: ##_! + 1 = &"; found; i; fct+1
if isPrime(fct-1) then
foundEnd = found + 1If
i += 1
print using("##", found); ": "; using("##", i); "! - 1 = "; fct-1
Wend
end if
Sleep</syntaxhighlight>
if isPrime(fct+1) then
{{out}}
found = found + 1
<pre>First 10 factorial primes;
print using("##", found); ": "; using("##", i); "! + 1 = "; fct+1
1: 1! + 1 = 2
end if
2: i = i2! + 1 = 3
3: 3! - 1 = 5
wend</syntaxhighlight>
4: 3! + 1 = 7
5: 4! - 1 = 23
6: 6! - 1 = 719
7: 7! - 1 = 5039
8: 11! + 1 = 39916801
9: 12! - 1 = 479001599
10: 14! - 1 = 87178291199</pre>
 
==={{header|Gambas}}===
Line 215 ⟶ 214:
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{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}}===
Line 355 ⟶ 388:
31: 546!-1 -> 14130200926141832545..99999999999999999999 [1260 digits]
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vb">#include "isprime.bas"
#include "factorial.bas"
 
Print "First 10 factorial primes:"
Dim As Integer found = 0, i = 1
While found < 10
Dim As Integer fct = factorial (i)
If isprime(fct-1) Then
found += 1
Print Using "##: ##_! - 1 = &"; found; i; fct-1
End If
If isprime(fct+1) Then
found += 1
Print Using "##: ##_! + 1 = &"; found; i; fct+1
End If
i += 1
Wend
Sleep</syntaxhighlight>
{{out}}
<pre>First 10 factorial primes;
1: 1! + 1 = 2
2: 2! + 1 = 3
3: 3! - 1 = 5
4: 3! + 1 = 7
5: 4! - 1 = 23
6: 6! - 1 = 719
7: 7! - 1 = 5039
8: 11! + 1 = 39916801
9: 12! - 1 = 479001599
10: 14! - 1 = 87178291199</pre>
 
=={{header|J}}==
512

edits