Catalan numbers: Difference between revisions

Content added Content deleted
No edit summary
m (Updated Julia)
Line 1,470: Line 1,470:


=={{header|Julia}}==
=={{header|Julia}}==
From the Catalan package, returns the n-th Catalan number
<lang julia>function catalan(n)
<lang julia>function catalan(bn::Integer)
binomial(2n,n)/(n+1)
if bn < 0
throw(DomainError())
else
n = BigInt(bn)
end
return binomial(2n, n)/(n + 1)
end</lang>
end</lang>
{{out}}
{{out}}
<lang julia>julia> for n = 1:15 println(catalan(n)) end
<pre>julia> for n = 1:15 println(catalan(n)) end
1.0
1
2.0
2
5.0
5
14.0
14
42.0
42
132.0
132
429.0
429
1430.0
1430
4862.0
4862
16796.0
16796
58786.0
58786
208012.0
208012
742900.0
742900
2674440
2.67444e6
9694845</pre>
9.694845e6</lang>


=={{header|K}}==
=={{header|K}}==