C program to compute sin(x) using Taylor’s series

C program to compute sin(x) using Taylor’s series: In this program we will use taylor series to compute sin(x), code for the problem is given below.

Code for C program to compute sin(x) using Taylor’s series

#include <stdio.h>
#include <math.h>
int main()
{
  float fact(float);
  float sum = 0, x, range;
  int i, j;
  printf("Enter the X value:");
  scanf("%f", &x);
  x = x * 3.14 / 180.0;
  printf("Enter the range value:");
  scanf("%f", &range);
  for (i = 1, j = 1; i <= range; i++, j = j + 2)
  {
    if (i % 2 != 0)
      sum = sum + pow(x, j) / fact(j);
    else
      sum = sum - pow(x, j) / fact(j);
  }
  printf("%f", sum);
}
float fact(float x)
{
  int f = 1, i;
  for (i = 1; i <= x; i++)
    f = f * i;
  return f;
}

Output

Enter the X value:30
Enter the range value:4
0.499770

Read: C program to check whether the given number is prime or not


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment