The program is written here to print the value of sine series. Sine series is a series which is used to find the value of sin(x).
The expansion of the sine series is:
Here ‘x’ is the angle of which the value is to be calculated and ‘n’ is the number of terms.
# The value of ‘x’ will be taken as input from the user and the number of terms ‘n’ will also be taken as input.
# The value of x is given in degree. Then it is converted into its equivalent radian. The value of the sine series is then calculated.
# If the value of ‘x’ is 90 then the value of sin(x) = 1.
INPUT: The value of the angle and the number of terms.
OUTPUT: The value of sin(x)
PROCESS:
Step 1: [Taking the input]
Read n [number of terms]
Read x [the angle for which the value is to be calculated]
Step 2: [Finding the value of sin(x)]
Set s<-1
Set sum<-0
[Finding the sum of the series]
For i=1 to n incremented by 2 repeat
Set f<-1
[Finding the factorial]
For j=1 to i repeat
Set f<-f×j
[Finding the sum of the series]
Set sum<-sum+s × xi/f
Set s<-s×(-1)
[End of ‘for’ loop]
Print "The value of sin(x) is sum"
Step 3: Stop.
TIME COMPLEXITY:
for(i=1;i<=n;i=i+2)----------------------------------- O(n)
{
f=1;
//finding the factorial
for(j=1;j<=i;j++)---------------------------- O(i)
f=f*j;
//finding the sum of the series
sum=sum+s*(pow(x,i)/f);
s=s*-1;
}
The time complexity of this program is O(n*i) where ‘n’ is the number of terms, ‘i’ is the power of each term.
SPACE COMPLEXITY:
The space complexity of this program is O(1) as it requires a constant number of spaces to execute the program for any given input.
Related
Contributed by