#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));
system("pause");
return 0;
}
/* 你的代码将被嵌在这里 */
double funcos(double e, double x) {
double item = 1.0, cosx = 1.0, fenzi = 1.0, fenmu = 1.0;
int flag = -1;
for (int i = 2; fabs(item) >= e; i += 2) { //fabs(),求出函数的绝对值
fenmu *= (i * (i - 1));
fenzi *= (x * x);
item = 1.0 * flag * fenzi / fenmu;
cosx += item;
flag *= -1;
}
return cosx;
}
fenmu *= (i * (i - 1));
fenzi *= (x * x);
item = 1.0 * flag * fenzi / fenmu;
重点!!!