#include <stdio.h>
#include <math.h>
// 计算阶乘
double factorial(int n)
{
if (n == 0 || n == 1)
{
return 1;
}
else
{
double result = 1;
for (int i = 2; i <= n; i++)
{
result *= i;
}
return result;
}
}
// 计算sin(x)泰勒展开式前十项和
double sinTaylorSum(double x)
{
double sum = 0;
for (int i = 0; i < 10; i++)
{
int sign = (i % 2 == 0)? 1 : -1;
sum += sign * pow(x, 2 * i + 1) / factorial(2 * i + 1);
}
return sum;
}
int main()
{
double x;
scanf("%lf", &x);
double sinSum = sinTaylorSum(x);
printf("%.3lf\n",sinSum);
return 0;
}
[ New Thread ]
Problem 1111 >> 1111 |
241040500610 @ 2024-11-23 11:30:47
|