#include<stdio.h>
#include<math.h>
int main()
局顷态 {
int n=0
double x,sum=0
printf("please enter x:")
scanf("桐源乎蚂%lf",&x)//
double cosx(double x,int n)
do
{
sum=sum+cosx(x,n)
n=n+1
}
while(fabs(cosx(x,n))>1e-8)
printf("%9.8f\n",sum)
return 0
}
double cosx(double x,int n)
{
double p,q//
p=pow(x,2*n)
double fact(int n)//
q=fact(2*n)
if(n%2)
return(-p/q)
else
return(p/q)
}
double fact(int n)//
{
double ans=1int i
if(n<=1)
return 1
for(i=1i<=n++i)
ans*=i
return ans
}
cosx函数即反余弦函数
函数y=cosx(x∈[0,π])的反函数叫做反余弦函数,
记作y=arccosx(x∈[-1,1]).
C语言程序:
#include <stdio.h>#include <math.h>
int main()
{
double x
double sum1, sum2, f = 1
int i, t = 1
printf("x:")
scanf("%lf"族答, &x)
i = 1
sum1 = sum2 = 1
for(i=2 i*=2)
{
f *= (i -1)
f *= i
t *= -1
sum2 += t * pow(x, i) / f
if(abs(sum2 - sum1) < 1e-6)
{
break
}
sum1 兆颂慧= sum2
}
printf("cos(%lf) = %lf\n", x, sum2)
return 樱樱0
}
运行测试:
x:2cos(2.000000) = -0.333333
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)