Program to find the value of sin ( nÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬¦½ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬¹ ÃƒÆ ’ Ã ¢ â ‚¬¦ Ãƒ ¢ Ã ¢ â € š ¬ Ã … â € œ ) | Javascript Program to find the value of sin ( n ? ) ; This function use to calculate the binomial coefficient upto 15 ; use simple DP to find coefficient ; Function to find the value of ; find cosTheta from sinTheta ; store required answer ; use to toggle sign in sequence . ; Driver code .
MAX = 16 var nCr = Array . from ( Array ( MAX ) , ( ) => new Array ( MAX ) ) ; function binomial ( ) { for ( var i = 0 ; i < MAX ; i ++ ) { for ( var 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 findCosNTheta ( sinTheta , n ) { var cosTheta = Math . sqrt ( 1 - sinTheta * sinTheta ) ; var ans = 0 ; var toggle = 1 ; for ( var 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 . toFixed ( 6 ) ; } binomial ( ) ; var sinTheta = 0.5 ; var n = 10 ; document . write ( findCosNTheta ( sinTheta , n ) ) ;