Catalan numbers: Difference between revisions

no edit summary
m (Automated syntax highlighting fixup (second round - minor fixes))
No edit summary
Line 2,187:
+----+------------+---------+-----------+
</pre>
 
=={{header|FutureBasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn Factorial( n as NSInteger ) as UInt64
UInt64 sum = 0
if n = 0 then sum = 1 : exit fn
sum = n * fn Factorial( n - 1 )
end fn = sum
 
local fn Catalan1( n as NSInteger ) as UInt64
UInt64 product = 1, result
NSUInteger i
for i = n + 2 to 2 * n
product = product * i
next
result = product / fn Factorial( n )
end fn = result
 
 
local fn Catalan2( n as NSInteger ) as UInt64
UInt64 sum = 0
NSUInteger i
if n = 0 then sum = 1 : exit fn
for i = 0 to n - 1
sum += fn Catalan2(i) * fn Catalan2( n - 1 - i )
next
end fn = sum
 
 
local fn Catalan3( n as NSInteger ) as UInt64
UInt64 result
if n = 0 then result = 1 : exit fn
result = fn Catalan3( n - 1 ) * 2 * ( 2 * n - 1 ) / ( n + 1 )
end fn = result
 
 
NSUInteger i
 
for i = 0 to 19
if( i < 16 )
NSLog( @"%3d.\t\t%7llu\t\t%12llu\t\t%12llu", i, fn Catalan1( i ), fn Catalan2( i ), fn Catalan3( i ) )
else
NSLog( @"%3d.\t\t%@\t\t%12llu\t\t%12llu", i, @"[-err-]", fn Catalan2( i ), fn Catalan3( i ) )
end if
next
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
0. 1 1 1
1. 1 1 1
2. 2 2 2
3. 5 5 5
4. 14 14 14
5. 42 42 42
6. 132 132 132
7. 429 429 429
8. 1430 1430 1430
9. 4862 4862 4862
10. 16796 16796 16796
11. 58786 58786 58786
12. 208012 208012 208012
13. 742900 742900 742900
14. 2674440 2674440 2674440
15. 9694845 9694845 9694845
16. [-err-] 35357670 35357670
17. [-err-] 129644790 129644790
18. [-err-] 477638700 477638700
19. [-err-] 1767263190 1767263190
</pre>
 
 
=={{header|Fōrmulæ}}==
 
715

edits