程序运行没报错?,fact函数计算阶乘功能未实现,product没初始,则默认为0,而且i从0开始,计算出的a阶乘永远是0,funcos中fact(i)作为除数了
随便写写试试
double funcos(double e, double x)
{
double b, d, n, r, i;
e = fabs(e), x *= x;
r = b = 0, d = n = 1;
while( fabs(i = d / n) > e ) {
r += i;
d *= x, n *= - b * (b+1);
b += 2;
}
return r;
}
#include
#include
double funcos(double x,double e)
{
double s=0,t=1,n=0;
while(fabs(t)>e)
{
s=s+t;
t=(t*(-1)*x*x)/((n+1)*(n+2));
n=n+2;
}
return s;
}
main()
{
double x,e,s;
scanf("%lf%lf",&x,&e);
s=funcos(x,e);
printf("cos x=%lf",s);
}