#include <stdio.h>
#include <math.h>

double sine(double x, int n) {
    double result = x;
    double term = x;
    int sign = -1;
    int denominator = 3;

    for (int i = 1; i < n; i++) {
        term *= (x * x) / (denominator * (denominator - 1));
        result += sign * term;
        sign *= -1;
        denominator += 2;
    }

    return result;
}

int main() {
    double angle;
    int terms;

    printf("Enter the angle in radians: ");
    scanf("%lf", &angle);

    printf("Enter the number of terms in the Taylor series: ");
    scanf("%d", &terms);

    double result = sine(angle, terms);
    double standard_sin = sin(angle);

    printf("Approximated sin(%.2f) using %d terms: %.6f\n", angle, terms, result);
    printf("Actual sin(%.2f): %.6f\n", angle, standard_sin);

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: