求近似值 各位,帮我看看下面的程序要怎样修改才能达到目的
#include <stdio.h>
#include <math.h>
double funcos( double e, double x );
int main()
{
double e, x;
scanf("%lf %lf", &e, &x);
printf("cos(%.2f) = %.6f\n", x, funcos(e, x));
return 0;
}
double funcos( double e, double x )
{
int n=0,flag=-1;
long p=1;
double power,item,sum;
sum=0;
while (fabs(item)>=e)
{
power = pow(x,n);
p = fact(n);
item = flag*power/p;
sum = sum+item;
n =n+2;
flag = -flag;
}
return sum;
}
long fact (n)
{
int i;
long result =1;
for (i=2;i<=n;i++)
{
result*=i;
}
return result;
}