title: Sine function using Taylor expansion (C Programming)
body: <p><a href="http://www5.picturepush.com/photo/a/7232713/1024/Anonymous/2.jpg" rel="noreferrer">Here</a>  is the question..</p>
  
  <p>This is what I've done so far,</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  long int factorial(int m)
  {
      if (m==0 || m==1) return (1);
      else      return (m*factorial(m-1));
  }
  double power(double x,int n)
  {
      double val=1;
      int i;
      for (i=1;i&lt;=n;i++)
      {
          val*=x;
      }
      return val;
  }
  
  double sine(double x)
  {
      int n;
      double val=0;
      for (n=0;n&lt;8;n++)
      {
          double p = power(-1,n);
          double px = power(x,2*n+1);
          long fac = factorial(2*n+1);
          val += p * px / fac;
      }
      return val;
  }
  
  int main()
  {
      double x;
      printf("Enter angles in degrees: ");
      scanf("%lf",&amp;x);
      printf("\nValue of sine of %.2f is %.2lf\n",x,sine(x * M_PI / 180));
      printf("\nValue of sine of %.2f from library function is %.2lf\n",x,sin(x * M_PI / 180));
      return 0;
  }
  </code></pre>
  
  <p>The problem is that the program works perfectly fine from 0 to 180 degrees, but beyond that it gives error.. Also when I increase the value of <code>n</code> in <code>for (n=0;n&lt;8;n++)</code> beyond 8, i get significant error.. There is nothing wrong with the algorithm, I've tested it in my calculator, and the program seems to be fine as well.. I think the problem is due to the range of the data type.. what should i correct to get rid of this error? <br>
  Thanks..</p>