#include <stdio.h>
#include <math.h>
int main()
{
double x;
int n;
printf("Enter the value of x (in radians): \n");
scanf("%lf", &x);
printf("Enter the number of terms (n): \n");
scanf("%d", &n);
{
double result = 0.0;
double term = x;
int sign = -1;
for (int i = 3; i <= n; i += 2)
{
term *= (x * x) / (i * (i - 1));
result += sign * term;
sign *= -1;
}
double actualResult = sin(x);
printf("Approximation of sin(%.2lf) using %d terms: %.6lf\n", x, n, result);
printf("Actual sin(%.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: