Develop a program to compute Sin(x) using Taylor series approximation. Compare your result with the built-in Library function. Print both the result with appropriate messages.

All QuestionsCategory: C LanguageDevelop a program to compute Sin(x) using Taylor series approximation. Compare your result with the built-in Library function. Print both the result with appropriate messages.
nikhil.d asked 3 years ago
2 Answers
nikhil.d answered 3 years ago

#include <stdio.h>
#include <math.h>
#define PI 3.142
int main()
{
    int n, i;
    float deg, x, sum = 0, term = 0;
    printf(“Enter number of terms, say n\n”);
    scanf(“%d”, &n);
    printf(“Enter the degree\n”);
    scanf(“%f”, &deg);
    x = (deg * PI) / 180;
    printf(“In Radians = %f \n”, x);
    term = x;
    sum = term;
    for (i = 3; i <= n; i += 2)
    {
        term = (-term * x * x) / (i * (i – 1));
        sum = sum + term;
    }
    printf(“sin(%f)=%f\n”, deg, sum);
    printf(“Inbuilt function Sin(%f) = %f \n”, deg, sin(x));
    printf(“User function Sin(%f) = %f”, deg, sum);
}

Anonymous answered 3 years ago

Note: Change the double inverted comma ( ” ) in the code to avoid an error.