#include <stdio.h>
float cosinus(float x)
{
float sum = 1.0f;
float term = 1.0f;
int sign = -1;
int n = 2;
while (1)
{
// 递推计算下一项 x^n / n!
term = term * x * x / ((n - 1) * n);
float current = sign * term;
// 项绝对值小于0.001,停止,不加入总和
if (current > -0.001f && current < 0.001f)
{
break;
}
sum += current;
sign = -sign;
n += 2;
}
return sum;
}