double fact(int n)
{
double fact = 1.0;
int i;
for (i = 1;i <= n;i++)
{
fact = fact * i;
}
return fact;
}
double MySin(double x, double epsilon)
{
double sin = x;
int n = 3, m = 3;
int f = 1;
while (pow(x, m) / fact(n) > epsilon)
{
f = -f;
sin = sin + f * (pow(x, m) / fact(n));
m = m + 2;
n = n + 2;
}
return sin;
}
int main()
{
double x, epsilon;
scanf("%lf%lf", &x, &epsilon);
printf("%.15f\n", MySin(x, epsilon));
return 0;
}
用多项式来近似表示正弦函数sinx
最新推荐文章于 2023-01-15 13:05:06 发布