这里给出了无限级数展开的公式:
cos x = 1 - x2/2! + x4/4! - x6/6! +...
这里,x
是弧度,它取值范围-1 <= x <= 1
。
#include <stdio.h>
int main(){
double cosine, x = 0.7, z;
int j, q, flag, factorial, sign;
char ch;
cosine = 0;
sign = -1;
for (int i = 2; i <= 10; i += 2)
{
z = 1;
factorial = 1;
for (j = 1; j <= i; j++)
z = z * x;
factorial = factorial * j;
cosine += sign * z / factorial;
sign = - 1 * sign;
}
cosine = 1 + cosine;
printf("Cosine of %lf is %lf/n", x, cosine);
return(0);
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266692.html