title: Infinite series approximation of pi in C not terminating
body: <p>Here is my code, when using print statements it appeared to be an infinite loop:</p>
  
  <p>some potential issues i can troubleshoot are integer division, and perhaps figuring out if the algorithm terminates, and if it always has the correct output, perhaps there is some idiosyncrasy of the C language that I do not understand causing this issue?</p>
  
  <p>From my understanding as the sum tends to negative infinity it will cause the break statement to be triggered ending the algorithm once it reaches an approximation of epsilon precision.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
  
    double pi, sum, epsilon;
    long long i=1;
    long long max = 2147483647;
    printf("Pleas enter the desired accuracy epsilon : ");
    scanf("%f", &amp;epsilon);
    while (i&lt;max){
      if (i%2 == 0){
        sum = -4.0/(2.0*i-1);
      }else if (i%2 ==1){
        sum = (4.0/(2.0*i-1));
      }
      if (sum &lt; epsilon){
        break;
      }
      pi += sum;
    }
    printf("The value of pi approximated to epsion : %f is %f\n", epsilon, pi);
    return 0;
  }
  </code></pre>