calculate catalan numbers up to a billion
<p>I'm new to python (and programming in general), I was asked in my class to calculate Catalan numbers up to a billion but the program I wrote for it is not working as intended.</p>

<pre><code>    from numpy import division 
    C=1
    n=0
    while C&lt;=10000000000:
        print (C)
        C=(4*n+2)/(n+2)*C
        n=n+1
</code></pre>

<p>This is what it prints</p>

<p>1,
1,
2,
4,
8,
24,
72,
216,
648,
1944,
5832,
17496,
52488,
157464,
472392,
1417176,
4251528,
12754584,
38263752,
114791256,
344373768,
1033121304,
3099363912,
9298091736,</p>

<p>As you can see from my fourth iteration onwards, I get the wrong number and I don't understand why.</p>

<p>EDIT:
The mathematical definition I used is not wrong! I know the Wiki has another definition but this one is not wrong.
Co=1, Cn+1 = (4*n+2)/(n+2)*Cn</p>

<p>This is solved using recursion:</p>

<pre><code>def catalan(n):
    if n &lt;=1 :
        return 1

    res = 0
    for i in range(n):
        res += catalan(i) * catalan(n-i-1)

    return res

for i in range(10000000000):
    print (catalan(i))
</code></pre>

<p>you can read more about Catalan numbers <a href="http://www.geeksforgeeks.org/program-nth-catalan-number/" rel="nofollow">here</a> or <a href="http://mathworld.wolfram.com/CatalanNumber.html" rel="nofollow">here</a></p>

python