Catalan numbers: Difference between revisions

No edit summary
Line 92:
 
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f CATALAN_NUMBERS.AWK
# contributed by Dan Nielsen
BEGIN {
for (i=0; i<=15; i++) {
printf("%2d %10d\n",i,catalan(i))
}
exit(0)
}
function catalan(n, ans) {
if (n == 0) {
ans = 1
}
else {
ans = ((2*(2*n-1))/(n+1))*catalan(n-1)
}
return(ans)
}
</lang>
<p>output:</p>
<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
15 9694845
</pre>
 
=={{header|BASIC}}==
477

edits