#include <stdio.h>
#include <math.h>
int main() {
double x;
int n;
scanf("%lf", &x);
printf("Enter the value of x (in radians): %lf\n",x);
scanf("%d", &n);
printf("Enter the number of terms (n):%d \n",n);
double result = 1.0;
double term = 1.0;
int sign = -1;
for (int i = 2; i <= n; i += 2)
{
term *= (x * x) / (i * (i - 1));
result += sign * term;
sign *= -1;
}
double actualResult = cos(x);
printf("Approximation of cos(%.2lf) using %d terms: %.6lf\n", x, n, result);
printf("Actual cos(%.2lf) using math.h: %.6lf\n", x, actualResult);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: