[算法] 计算三角函数
该公式用于计算正弦(X) 另三角函数如下:

VD计算正弦(X) , X每弧度
#include <stdio.h>
#include <stdlib.h>
int main()
{
double sinx, temp, x; // x tinh theo radian
int i = 0;
scanf("%lf", &x);
sinx = temp = x;
while (temp > 0.000001 || temp < -0.000001) // lam tron den 5 so thap phan
{
i++;
temp = temp*x/(2*i+1)*x/(2*i); // x^(2i+1)/(2i+1)!
if (i%2==0) sinx = sinx + temp;
else sinx = sinx - temp;
}
printf("%.5f",sinx);
return 0;
}
也许是因为数据的类型或某些其他原因,仅精确到-27的<= X<与X = 27%弧度.
在上面的代码,我们不指望函数x ^(2I 1) 和 (2I 1)! 除了这意味着连续性临时TEMP = X ^计算(2I 1) / (2I 1)! 为了避免大量的x的溢出.
从这里我们可以建立计算其他三角函数.
请参阅:
三角函数



宝宝可以计算C编程叶片是不是 !
有NHE. 您可以使用库,并使用该函数math.h中腥(X) 计算腥NHE.