题目链接: 习题5-7 使用函数求余弦函数的近似值 (15分)
#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;
}
#include<math.h>
double funcos( double e
, double x
){
double s
=0,p
=1,t
;
int i
=0,f
=1,j
;
do{
for(j
=1;j
<=i
;j
++){
p
=p
*j
;
}
t
=f
*pow(x
,i
)/p
;
s
=s
+t
;
p
=1;
f
=-f
;
i
+=2;
}while(fabs(t
)>=e
);
return s
;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-61618.html