123. C Program to Compute the 1-x3/3!+x5/5!–x7/7!+ …………………xn/n! sine series.
How does this program work?
- This program is used to compute the sum of series for the given cosine order.
- Here we are going to find the series for 1-x3/3!+x5/5!–x7/7! + …………………………. xn/n!upto nth term.
- where The nth term is the user input.
- Computing the given series is easy by Using the simple for loop condition and by using the sine equation.
Here is the code
#include <stdio.h>
int main(void)
{
int i, n;
float x, sum, t;
printf(" Enter the value for x : \n");
scanf("%f",&x);
printf(" Enter the value for n : \n");
scanf("%d",&n);
x=x*3.14159/180;
t=x;
sum=x;
/* Loop to calculate the value of Sine */
for(i=1;i<=n;i++)
{
t=(t*(-1)*x*x)/(2*i*(2*i+1));
sum=sum+t;
}
printf(" The value of Sin(%f) = %.4f",x,sum);
return 0;
}