e){item=flag*pow(x,i)/function(i);sum=sum+item;flag=-flag;i=i+2;}return sum;}double function(int i){int a;double fact;fac" /> e){item=flag*pow(x,i)/function(i);sum=sum+item;flag=-flag;i=i+2;}return sum;}double function(int i){int a;double fact;fac - 作业答案大全" />

这是一道C程的题目:输入精度e,用下列公式求cos x的近似值,精确到最后一位的绝对值小于e.要求定义和调用函数求函数近似值、cos(x) = x^0/0!-x^2/2!+x^4/4!-x^6/6!+……这是我的答案.为什么显示溢出?#include#includemain (){double e,x;double cos(double x);scanf("%lf%lf",&e,&x);printf("%f\n",cos(x));return 0;}double cos(double x){int i,flag;double e,sum,item;double function(int i);flag=1;i=0;sum=0;while(fabs(item)>e){item=flag*pow(x,i)/function(i);sum=sum+item;flag=-flag;i=i+2;}return sum;}double function(int i){int a;double fact;fac

问题描述:

这是一道C程的题目:输入精度e,用下列公式求cos x的近似值,精确到最后一位的绝对值小于e.
要求定义和调用函数求函数近似值、cos(x) = x^0/0!-x^2/2!+x^4/4!-x^6/6!+……
这是我的答案.为什么显示溢出?
#include
#include
main ()
{
double e,x;
double cos(double x);
scanf("%lf%lf",&e,&x);
printf("%f\n",cos(x));
return 0;
}
double cos(double x)
{
int i,flag;
double e,sum,item;
double function(int i);
flag=1;
i=0;
sum=0;
while(fabs(item)>e){
item=flag*pow(x,i)/function(i);
sum=sum+item;
flag=-flag;
i=i+2;
}
return sum;
}
double function(int i)
{
int a;
double fact;
fact=1.00;
for(a=2;a