title: Cosine Calculation without cmath library
body: <p>I am a computer science student. I have been assigned a project where I need to create a small program using C++ which will ask for degrees or radians and then output the sin, cos and tan values but I can only use <code>#include  &lt;iostream&gt;</code>. The sine value is working fine but the cosine value is the problem. This is the code I use to calculate: </p>
  
  <pre><code>float rad = radian value;
  
  float func_cos (float rad)
  {
      float cos;
      int i = 0;
      float sum = 0;
      float x = rad;
  
      while (fabs(x) &gt; 0.000001)
      {
          i = i + 2;
          x = -(x) * ((rad*rad)/(i*(i-1)));
          sum = (sum) + (x);
      }
      cos = 1 - sum;
  
      return cos;
  }   
  </code></pre>