#include <iostream>
#include <cmath> // for pow() function
using namespace std;
// Recursion method :
http://web.eecs.utk.edu/~cs102/lectures/recursion.html
float factorial(float number)
{
if (number == 0) return 1;
return number * factorial(number-1);
}
float DegToRad(float degree)
{
float radians = (degree / 360) * (2.0 * M_PI);
return radians;
}
/*
* Refer here for formulae :
http://www.youtube.com/watch?v=dp2ovDuWhro
*/
void cSIN(float radian, int aprox)
{
float result = 0.0;
for(int x=1; x<aprox; x++)
{
float firstPart = pow (-1, (x+1)); //(-1)^n+1
float secondPart = pow(radian,((2*x)-1)); // x^2n-1
float thirdPart = factorial((2*x)-1); // (2n-1)!
result = result + firstPart*(secondPart/thirdPart);
}
cout<<"Result = "<<result<<endl;
}
int main()
{
cSIN(DegToRad(35),10);
return 0 ;
}
This is what i made so far to compute sine value. I need help to compute cosine value. Please help me