C Program For Sine Series
Let's first define a Sine Series before moving on to the Sine Series' programme.
Sine Series:
To determine the value of Sin(x), one uses the Sine Series, where x represents the transformed angle from degrees to radians.
Sin(x) is represented as a sine series by the formula:
![C Program For Sine Series](https://static.tutorialandexample.com/c/c-program-for-sine-series1.png)
Using the above notation in its entirety, the sine series formula is
![C Program For Sine Series](https://static.tutorialandexample.com/c/c-program-for-sine-series2.png)
For instance, Give x a value of 30.
![C Program For Sine Series](https://static.tutorialandexample.com/c/c-program-for-sine-series3.png)
Therefore, 0.52359 is the radian value for 30 degrees.
![C Program For Sine Series](https://static.tutorialandexample.com/c/c-program-for-sine-series4.png)
Therefore, Sin (30) has a value of 0.5.
Implementing Sine Series Program in C:
#include<stdio.h>
void main()
{
int i, n;
float x, sum, temp;
printf(" Enter the value for x : ");
scanf("%f",&x);
printf(" Enter the value for n : ");
scanf("%d",&n);
x=x*3.14159/180;
temp=x;
sum=x;
/* Loop to calculate the sine value by performing series*/
for(i=1;i<=n;i++)
{
temp = (temp *(-1)*x*x)/(2*i*(2*i+1));
sum=sum+temp;
}
printf(" The value of Sine(%f) = %.4f",x,sum);
}
OUTPUT:
![C Program For Sine Series](https://static.tutorialandexample.com/c/c-program-for-sine-series5.png)
Explanation:
1. 'x' to a radian value conversion
2. x = x * 3.14159 / 180 (x = 45 * 3.14159 / 180) So, x=0.785398
3. It assigns temp=x and sum=x, meaning that t and sum are both equal to 0.785398.
It sets the value of to 1, and the loop keeps running until the for loop's condition is satisfied.
3.1. The loop condition is satisfied when i<=n (1<=4).
temp = (0.785398 * (-1) * 0.785398 * 0.785398)/(2 * 1 * (2 * 1 + 1))
So, temp = -0.08074
sum = 0.785398 + (- 0.08074)
So, sum=0.70465
i++
So, i=2
3.2. The for loop condition is valid when i<=n (2<=4)
temp = (- 0.08074 * (-1) * 0.785398 * 0.785398)/(2 * 2 * (2 * 2 + 1))
So, temp = 0.00249
sum = 0.70465 + 0.00249
So, sum=0.70714
i++
So, i=3
3.3The loop condition is satisfied when i<=n (3<=4).
temp = (0.00249 * (-1) * 0.785398 * 0.785398)/(2 * 3 * (2 * 3 + 1))
So, temp = -0.000032
sum = 0.70714 + (- 0.000032)
So, sum=0.707108
i++
So, i=4
3.4. The for loop condition i<=n (4=4) is true.
temp = (- 0.000032 * (-1) * 0.785398 * 0.785398)/(2 * 4 * (2 * 4 + 1))
So, temp = 0.000000274
sum = 0.707108 + 0.000000274
So, sum=0.707108274
i++
So, i=5
3.5. The loop condition is false for i<=n (but 5>4).
It is terminated from the for loop.
4. After that, it prints. Sin (0.785398) = 0.7071 is the value.
5. Programme execution is finished as a result.
The Graph for Sine Series is given by:
![C Program For Sine Series](https://static.tutorialandexample.com/c/c-program-for-sine-series6.png)