Program to find the value of sin(nΘ)
Given the value of sin(Θ) and a variable n<=15. The task is to find the value of sin(nΘ) using propety of trignometric functions.
Examples:
Input: sin(Θ)=0.5, n=1 Output: 0.5 Input: sin(Θ)=0.5, n=10 Output: -0.866025
Approach: This problem can be solved using De moivre’s theoremand Binomial theorem

Now, we have both sin(Θ) and cos(Θ). Put the value in equation to get your answer.
Below is the implementation of above approach:
C++
// C++ Program to find the value of sin(n?) #include <bits/stdc++.h> #define ll long long int #define MAX 16 using namespace std; ll nCr[MAX][MAX] = { 0 }; // This function use to calculate the // binomial cofficient upto 15 void binomial() { // use simple DP to find cofficient for (int i = 0; i < MAX; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) nCr[i][j] = 1; else nCr[i][j] = nCr[i - 1][j] + nCr[i - 1][j - 1]; } } } // Function to find the value of double findCosNTheta(double sinTheta, ll n) { // find cosTheta from sinTheta double cosTheta = sqrt(1 - sinTheta * sinTheta); // store required answer double ans = 0; // use to toggle sign in sequence. ll toggle = 1; for (int i = 1; i <= n; i += 2) { ans = ans + nCr[n][i] * pow(cosTheta, n - i) * pow(sinTheta, i) * toggle; toggle = toggle * -1; } return ans; } // Driver code. int main() { binomial(); double sinTheta = 0.5; ll n = 10; cout << findCosNTheta(sinTheta, n) << endl; return 0; } |
chevron_right
filter_none
Java
// Java Program to find the value of sin(n?) public class GFG { private static final int MAX = 16; static long nCr[][] = new long [MAX][MAX]; // This function use to calculate the // binomial coefficient upto 15 static void binomial() { // use simple DP to find cofficient for (int i = 0; i < MAX; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) nCr[i][j] = 1; else nCr[i][j] = nCr[i - 1][j] + nCr[i - 1][j - 1]; } } } // Function to find the value of static double findCosNTheta(double sinTheta, int n) { // find cosTheta from sinTheta double cosTheta = Math.sqrt(1 - sinTheta * sinTheta); // store required answer double ans = 0; // use to toggle sign in sequence. long toggle = 1; for (int i = 1; i <= n; i += 2) { ans = ans + nCr[n][i] * Math.pow(cosTheta, n - i) * Math.pow(sinTheta, i) * toggle; toggle = toggle * -1; } return ans; } // Driver code public static void main (String args[]){ binomial(); double sinTheta = 0.5; int n = 10; System.out.println(findCosNTheta(sinTheta, n)); } // This code is contributed by ANKITRAI1 } |
chevron_right
filter_none
Python3
# Python3 program to find the # value of sin(n-theta) import math MAX=16nCr=[[0 for i in range(MAX)] for i in range(MAX)] # Fucntion to calculate the binomial # cofficient upto 15 def binomial(): # use simple DP to find cofficient for i in range(MAX): for j in range(0,i+1): if j == 0 or j == i: nCr[i][j] = 1 else: nCr[i][j] = nCr[i - 1][j] + nCr[i - 1][j - 1] # Function to find the value of cos(n-theta) def findCosNTheta(sinTheta,n): # find sinTheta from sinTheta cosTheta = math.sqrt(1 - sinTheta * sinTheta) # to store required answer ans = 0 # use to toggle sign in sequence. toggle = 1 for i in range(1,n+1,2): ans = (ans + nCr[n][i]*(cosTheta**(n - i)) *(sinTheta**i) * toggle) toggle = toggle * -1 return ans # Driver code if __name__=='__main__': binomial() sinTheta = 0.5 n = 10 print(findCosNTheta(sinTheta, n)) # this code is contributed by sahilshelangia |
chevron_right
filter_none
C#
// C# Program to find the value of sin(n?) using System; class GFG { private static int MAX = 16; static long[,] nCr = new long [MAX, MAX]; // This function use to calculate the // binomial coefficient upto 15 static void binomial() { // use simple DP to find cofficient for (int i = 0; i < MAX; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) nCr[i, j] = 1; else nCr[i, j] = nCr[i - 1, j] + nCr[i - 1, j - 1]; } } } // Function to find the value of cos(n-theta) static double findCosNTheta(double sinTheta, int n) { // find cosTheta from sinTheta double cosTheta = Math.Sqrt(1 - sinTheta * sinTheta); // store required answer double ans = 0; // use to toggle sign in sequence. long toggle = 1; for (int i = 1; i <= n; i += 2) { ans = ans + nCr[n, i] * Math.Pow(cosTheta, n - i) * Math.Pow(sinTheta, i) * toggle; toggle = toggle * -1; } return ans; } // Driver code public static void Main () { binomial(); double sinTheta = 0.5; int n = 10; Console.Write(findCosNTheta(sinTheta, n)); } } // This code is contributed by ChitraNayal |
chevron_right
filter_none
PHP
<?php // PHP Program to find the value of sin(n?) $MAX=16; $nCr=array_fill(0,$MAX,array_fill(0,$MAX,0)); // This function use to calculate the // binomial cofficient upto 15 function binomial() { global $MAX,$nCr; // use simple DP to find cofficient for ($i = 0; $i < $MAX; $i++) { for ($j = 0; $j <= $i; $j++) { if ($j == 0 || $j == $i) $nCr[$i][$j] = 1; else $nCr[$i][$j] = $nCr[$i - 1][$j] + $nCr[$i - 1][$j - 1]; } } } // Function to find the value of function findCosNTheta($sinTheta,$n) { global $MAX,$nCr; // find cosTheta from sinTheta $cosTheta = sqrt(1 - $sinTheta * $sinTheta); // store required answer $ans = 0; // use to toggle sign in sequence. $toggle = 1; for ($i = 1; $i <= $n; $i += 2) { $ans = $ans + $nCr[$n][$i] * pow($cosTheta, $n - $i) * pow($sinTheta, $i) * $toggle; $toggle = $toggle * -1; } return $ans; } // Driver code. binomial(); $sinTheta = 0.5; $n = 10; echo findCosNTheta($sinTheta, $n); // this code is contributed by mits ?> |
chevron_right
filter_none
Output:
-0.866025
Recommended Posts:
- Program to find sum of 1 + x/2! + x^2/3! +...+x^n/(n+1)!
- C++ Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n!
- Program to find the Depreciation of Value
- Program to find last two digits of 2^n
- Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Program to find Sum of the series 1*3 + 3*5 + ....
- Program to find the sum of a Series (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n)
- Program to find sum of series 1*2*3 + 2*3*4+ 3*4*5 + . . . + n*(n+1)*(n+2)
- Program to find the sum of a Series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n
- Program to Find the value of cos(nΘ)
- Program to find sum of the given sequence
- Program to find the value of tan(nΘ)
- Program to find HCF iteratively
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



