Catalan numbers: Difference between revisions

Added ZX81 BASIC
(→‎{{header|Perl 6}}: not sure why there was a 15 here :/)
(Added ZX81 BASIC)
Line 306:
14 2674440
15 9694845
 
==={{header|Sinclair ZX81 BASIC}}===
Works with 1k of RAM.
 
The specification asks for the first 15 Catalan numbers. A lot of the other implementations produce either C(0) to C(15), which is 16 numbers, or else C(1) to C(15)—which is 15 numbers, but I'm not convinced they're the first 15. This program produces C(0) to C(14).
 
<lang basic> 10 FOR N=0 TO 14
20 LET X=N
30 GOSUB 130
40 LET A=FX
50 LET X=N+1
60 GOSUB 130
70 LET B=FX
80 LET X=2*N
90 GOSUB 130
100 PRINT N,FX/(B*A)
110 NEXT N
120 STOP
130 LET FX=1
140 FOR I=1 TO X
150 LET FX=FX*I
160 NEXT I
170 RETURN</lang>
{{out}}
<pre>0 1
1 1
2 2
3 5
4 14
5 42
6 132
7 429
8 1430
9 4862
10 16796
11 58786
12 208012
13 742900
14 2674440</pre>
 
=={{header|BBC BASIC}}==
519

edits