title: Write log function without math library?
body: <p>Write the</p>
  
  <pre><code>function double mylog( double  y);
  </code></pre>
  
  <p>Which computes the natural logarithm of y when <code>y&gt;0</code>.  Do this by summing the terms of the power series,</p>
  
  <pre><code>mylog( y ) = 2*( x + x^3/3 + x^5/5 + x^7/7 + x^9 /9 + … ) 
  </code></pre>
  
  <p>Sum the terms up to <code>x^151</code>. Notice that the parameter y is NOT the x of the power series. Before computing the power series, calculate x:</p>
  
  <pre><code>x = (y‐1)/(y+1)
  </code></pre>
  
  <p>Write the function to be side‐effect free (no I/O, no output, no globals). If <code>y&lt;=0.0</code> then  <code>return 0</code>. (The actual math.h function does something better than this.) For example, for <code>mylog( 3 )</code>, <code>x = 2/5 = .4</code>
  <code>mylog( 3 ) = 2*( 0.4 + 0.4^3/3 + 0.4^5/5 + 0.4^7/7 + 0.4^9/9 + … ) ≈ .8473</code>
  Your loop can keep a variable xpow that builds up the increasing powers of x so you don’t need a nested loop for that.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  double  mylog(double y)
  {
  double x = (y-1)/(y+3);
  double sum = 1.0;
  double xpow=x;
  
  for(int n = 1; n &lt;= 151; n++)
  {
  
  if(n%2!=0)
  {
  
  sum = sum + xpow/(double)n;
  }
  xpow = xpow * x;
  
   }    
  
   sum *= 2;
  
   return sum;
   }
  
   int main()
   {
  double num;
  
  printf("Enter Number ");
  scanf("%lf", &amp;num);
  
  num = mylog(num);
  printf("%lf \n", num);
  system("pause");
    }
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>