微软笔试题求sine函数
如题
[解决办法]
double Sine(double x)
{
const double epsilon = 1.0e-8;
double res = 0.0;
double delta = x;
int i = 2;
while (fabs(delta) >= epsilon) {
res += delta;
delta *= -x * x / i / (i + 1);
}
return res;
}
double Sine(double x)
{
const double epsilon = 1.0e-8;
double res = 0.0;
double delta = x;
int i = 2;
while (fabs(delta) >= epsilon) {
res += delta;
delta *= -x * x / i / (i + 1);
i += 2;
}
return res;
}