Find other two sides and angles of a right angle triangle | Javascript program to print all sides and angles of right angle triangle given one side ; Function to find angle A Angle in front of side a ; applied cosine rule ; convert into degrees ; Function to find angle B Angle in front of side b ; applied cosine rule ; convert into degrees and return ; Function to print all angles of the right angled triangle ; for calculate angle A ; for calculate angle B ; Function to find other two sides of the right angled triangle ; if n is odd ; case of n = 1 handled separately ; case of n = 2 handled separately ; Print angles of the triangle ; Driver Code
let PI = 3.1415926535 ; function findAnglesA ( a , b , c ) { let A = Math . acos ( ( b * b + c * c - a * a ) / ( 2 * b * c ) ) ; return A * 180 / PI ; } function findAnglesB ( a , b , c ) { let B = Math . acos ( ( a * a + c * c - b * b ) / ( 2 * a * c ) ) ; return B * 180 / PI ; } function printAngles ( a , b , c ) { let x = a ; let y = b ; let z = c ; let A = findAnglesA ( x , y , z ) ; let B = findAnglesB ( x , y , z ) ; document . write ( " " + A + " " + B + " " + 90 ) ; } function printOtherSides ( n ) { let b = 0 , c = 0 ; if ( ( n & 1 ) > 0 ) { if ( n == 1 ) document . write ( - 1 ) ; else { b = ( n * n - 1 ) / 2 ; c = ( n * n + 1 ) / 2 ; document . write ( " " + b + " " + c ) ; } } else { if ( n == 2 ) document . write ( - 1 ) ; else { b = n * n / 4 - 1 ; c = n * n / 4 + 1 ; document . write ( " " + b + " " + c + " " ) ; } } printAngles ( n , b , c ) ; } let a = 12 ; printOtherSides ( a ) ;