Making c/++ function to compute sin(x)
Referancing by the formula;
But i don't know where to stop infinity sum, and i don't want libraries for quick-answer. I want to make it. I made factorial function well. (fact() function)
double sin(int x) {
int tp=0;
for(int k=1; ;k++)
{
tp+=pow(-1,k)*pow(x,2*k+1)/fact(2*k+1);
}
return tp;
}
I ran the loop by 8 times, it's approaching to true value if you improve loop timing. Thanks @Sreeram TP
double sin(int x) {
int tp=0;
for(int k=1;k<8 ;k++)
{
tp+=pow(-1,k)*pow(x,2*k+1)/fact(2*k+1);
}
return tp;
}