title: Calculating Pi using GMP
body: <p>I'm trying to calculate Pi using <a href="http://gmplib.org/" rel="nofollow noreferrer">GMP</a>(5.1.0) with this series:
  <img src="https://i.stack.imgur.com/z4ZMY.png" alt="Pi = 3 + 4 / (2 * 3 * 4) - 4 / (4 * 5 * 6) + 4 / (6 * 7 * 8) - ..."></p>
  
  <p><strong>What i have done is:</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;gmp.h&gt;
  
  mpz_t pi;
  mpz_t next; // Every number in the serie that comes after 3
  
  int a = 2, b = 3, c = 4; // Divisors. Everytime add 2 to all of them at the end of the loop
  int i; // Loop counter
  
  int main (void) {
      mpz_init (pi); mpz_init (next);
      mpz_set_str (pi, "3", 10);
  
      for (i = 2 ;; ++i) {
          printf ("%s\n", mpz_get_str (NULL, 10, pi));
  
          mpz_set_d (next, 4 / (a * b * c));
  
          if (i % 2 == 0)
              mpz_add (pi, pi, next);
          else
              mpz_sub (pi, pi, next);
  
          a += 2; b += 2; c += 2;
      }
  
      mpz_clear (next);
      mpz_clear (pi);
  }
  </code></pre>
  
  <p><strong>I'm compiling on 64 bit Linux:</strong></p>
  
  <pre><code>gcc -Wall -pedantic -o foo foo.c -lgmp
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>3
  3
  3
  and so on
  </code></pre>
  
  <p><strong>Expected Output:</strong></p>
  
  <pre><code>3
  3.1666...
  3.1333...
  3.1452...
  3.1396...
  and so on
  </code></pre>
  
  <hr>
  
  <p>Any help will be greatly appreciated.</p>