title: Implementing Taylor Series for sine and cosine in C
body: <p>I've been following the guide my prof gave us, but I just can't find where I went wrong.  I've also been going through some other questions about implementing the Taylor Series in C.</p>
  
  <p><a href="https://i.stack.imgur.com/sG2mY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sG2mY.png" alt="enter image description here"></a></p>
  
  <p>Just assume that RaiseTo(raise a number to the power of x) is there.</p>
  
  <pre><code>double factorial (int n)
  {
      int fact = 1,
      flag;
  
     for (flag = 1; flag &lt;= n; flag++)
     {
          fact *= flag;
     }
  
     return flag;
  }
  
  double sine (double rad)
  {
  
  int flag_2,
      plusOrMinus2 = 0; //1 for plus, 0 for minus 
  double sin, 
      val2 = rad,
      radRaisedToX2,
      terms;
  
  terms = NUMBER_OF_TERMS; //10 terms
  
      for (flag_2 = 1; flag_2 &lt;= 2 * terms; flag_2 += 2)
      {
          radRaisedToX2 = RaiseTo(rad, flag_2);   
  
          if (plusOrMinus2 == 0)
          {
              val2 -=  radRaisedToX2/factorial(flag_2);
              plusOrMinus2++; //Add the next number
          }
  
          else
          {
              val2 += radRaisedToX2/factorial(flag_2);
              plusOrMinus2--; //Subtract the next number
          }
      }
  
      sin = val2;
      return sin;
   }
  
  int main()
  {
      int degree;
      scanf("%d", &amp;degree);
      double rad, cosx, sinx;
      rad = degree * PI / 180.00;
      //cosx = cosine (rad);
      sinx = sine (rad);
      printf("%lf \n%lf", rad, sinx);
  }
  </code></pre>
  
  <p>So during the loop, I get the rad^x, divide it by the factorial of the odd number series starting from 1, then add or subtract it depending on what's needed, but when I run the program, I get outputs way above one, and we all know that the limits of sin(x) are 1 and -1, I'd really like to know where I went wrong so I could improve, sorry if it's a pretty bad question.</p>