老哥们 求问这段代码哪里出错了 为啥不符合答案 题目是习题5-7 使用函数求余弦函数的近似值 (15分)

题目图片说明
我的代码是
double funcos( double e, double x ){
double m=0;
int flag=1;
double temp=0;
double g=0;
double f=0;
do {
for (int i=1;i<=f;i++){
g*=i;
}
m=pow(x,f)/g;
f+=2;
temp+=m*flag;
flag=-flag;

}while(fabs(m)<e);
return temp;

}
报错是0 sample等价,计算量较小

答案错误
3 ms 128 KB
1 精度高,不可直接计算阶乘

答案错误
3 ms 364 KB
2 特殊点pi/2

答案错误
3 ms 256 KB
3 特殊点0

答案错误
2 ms 356 KB
求好心人 帮忙
感激不尽

g得等于1 不然永远乘0 还有循环一次之后要复位
double funcos( double e, double x ){
double m=0;
int flag=1;
double temp=0;
double g=1;
int f=0;
int i;
do {
for ( i=1;i<=f;i++){
g*=i;
}
m=pow(x,f)/g;
f+=2;
temp+=m*flag;
flag=-flag;
g=1;
}while(m>e);
return temp;
}

for (int i=1;i<=f;i++){
浮点数和整数比较,不能出现=,因为有精度误差。