Program to find third side of triangle using law of cosines | Function to calculate cos value of angle c ; Converting degrees to radian ; Maps the sum alet the series ; Holds the actual value of sin ( n ) ; Function to find third side ; Driver code ; function call
function cal_cos ( n ) { let accuracy = 0.0001 , x1 ; let denominator , cosx , cosval ; n = n * ( 3.142 / 180.0 ) ; x1 = 1 ; cosx = x1 ; cosval = Math . cos ( n ) ; let i = 1 ; do { denominator = 2 * i * ( 2 * i - 1 ) ; x1 = - x1 * n * n / denominator ; cosx = cosx + x1 ; i = i + 1 ; } while ( accuracy <= Math . abs ( cosval - cosx ) ) ; return cosx ; } function third_side ( a , b , c ) { let angle = cal_cos ( c ) ; return Math . sqrt ( ( a * a ) + ( b * b ) - 2 * a * b * angle ) ; } let c = 49 ; let a = 5 , b = 8 ; document . write ( Math . round ( third_side ( a , b , c ) * 100000.0 ) / 100000.0 ) ;