Catalan numbers: Difference between revisions

Content added Content deleted
(Dialects of BASIC moved to the BASIC section.)
(→‎{{header|PL/0}}: Added a solution.)
Line 4,491: Line 4,491:
13 => 742900 742900 742900
13 => 742900 742900 742900
14 => 2674440 2674440 2674440</pre>
14 => 2674440 2674440 2674440</pre>

=={{header|PL/0}}==
{{trans|Tiny BASIC}}
Integers are limited to 32767 so only the first ten Catalan numbers can be represented. To avoid internal overflow, the program subtracts something clever from <code>c</code> and then adds it back at the end.
<syntaxhighlight lang="pascal">
var n, c, i;
begin
n := 0; c := 1;
! c;
while n <= 9 do
begin
n := n + 1;
i := 0;
while c > 0 do
begin
c := c - (n + 1);
i := i + 1
end;
c := 2 * (2 * n - 1) * c / (n + 1);
c := c + 2 * i * (2 * n - 1);
! c
end;
end.
</syntaxhighlight>
{{out}}
<pre>
1
1
2
5
14
42
132
429
1430
4862
16796
</pre>

=={{header|PL/I}}==
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">catalan: procedure options (main); /* 23 February 2012 */
<syntaxhighlight lang="pl/i">catalan: procedure options (main); /* 23 February 2012 */