title: Calculating the taylor series of sinx in C
body: <p>I have to calculate the taylor series of sinx down to 4 decimals. So far my code looks like this:</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  
  float pwr(int n, float x){ //power of x to the n
      int i;
      float p=x;
  
      for(i=1; i&lt;=n; i++){
          p=p*x;
      }
      return p;
  }
  
  int fac(int n){ //n factorial
      int i;
      int f=1;
      for(i=1; i&lt;=n; i++){
          f=f*i;
      }
      return f;
  }
  
  int main(){
      int i, k;
      int sign;
      float rad, num, den, deg;
      float sum=0.f;
      
      printf(&quot;How many iterations of the series should I add? &quot;);
      scanf(&quot;%d&quot;, &amp;k);
      while(k&lt;1){
          printf(&quot;I can't add negative or 0 iterations. Please enter valid input: &quot;);
          scanf(&quot;%d&quot;, &amp;k);
      }
      
      printf(&quot;Enter angle in degrees: &quot;);
      scanf(&quot;%f&quot;, &amp;deg);
      rad=deg*M_PI/180; //convert to radians
      
      for(i=1; i&lt;=k; i++){ //taylor series of sinx: [(-1)^n]*[{x^(2n+1)}/(2n+1)!]
          sign=pwr(i, -1); //finds (-1)^n
          
          //finds x^(2n+1) by expanding it as [(x^n)^2]*x
          num=pwr(i, rad); //x^n
          num=num*num; //(x^n)^2
          num=num*rad; //[(x^n)^2]*x
          
          //finds (2n+1)!
          den=fac(2i+1);
          
          //sum
          sum=sum+sign*(num/den);
      }
      
      printf(&quot;The sum is %.4f&quot;, sum);
      return 0;
  }
  </code></pre>
  <p>I tried to break down the sum in different parts that I would add up at the end of each loop. For some reason it won't return any value. For example, if I tried to run the program by repeating the loop 100 times and entered 156 degrees the program returns -1.#INF and below it says the process exited with a return value of 18. What am I doing wrong?</p>