title: C: Find member of the sequence by given criteria
body: <p>I need help with the following C program:</p>
  
  <p>For input value <code>EPS</code> which represents precision (<code>double</code> value), print first member of sequence so that the statement</p>
  
  <pre><code>abs(a(n)-a(n-1))&lt;EPS
  </code></pre>
  
  <p>is true.</p>
  
  <p>Sequence <code>a(n)</code> is given by:</p>
  
  <pre><code>a(n)=(1-1/2!)(1+1/3!)...(1+(-1)^n/(n+1)!)
  </code></pre>
  
  <p>I used this equation: <code>a(n)-a(n-1)=((-1)^n*(n+2))/(n+1)!</code></p>
  
  <p>My code doesn't give me any output:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  
  int fact(int n)//function to find factorial of 'n'
  {
   int i,f=1;
   for(i=1;i&lt;=n;i++)
          f=f*i;
   return f;
  }
  
  int main()
  {
      double an=0.5,ap=2,EPS;//an is a_new, ap is a_previous
      int n=1;
      printf("EPS=");
      scanf("%lf",&amp;EPS);
      do
      {
       int f=fact(n+1);
       n=n+1;
       an=ap+((double)(pow(-1.0,n)*(n+2)))/f;
      }
      while(fabs(an-ap)&gt;EPS);
      printf("%lf",an);
      return 0;
  }
  </code></pre>
  
  <p>Thanks for replies.</p>