代码展示如下:
#include <stdio.h>
int main()
{
double x,cos,t,temp;
int n, i;
while (scanf("%lf %d", &x, &n)!= EOF)
{
t=x*x;
temp=1.0;
cos=1.0;
for(i=1;i<=n;i++)
{
temp*=-t;
temp/=(i*2-1)*(i*2);
cos+=temp;
}
printf("%.4lf\n", cos);
}
return 0;
}