Find other two sides and angles of a right angle triangle | PHP 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
< ? php $ PI = 3.1415926535 ; function findAnglesA ( $ a , $ b , $ c ) { global $ PI ; $ A = acos ( ( $ b * $ b + $ c * $ c - $ a * $ a ) / ( 2 * $ b * $ c ) ) ; return $ A * 180 / $ PI ; } function findAnglesB ( $ a , $ b , $ c ) { global $ PI ; $ B = acos ( ( $ a * $ a + $ c * $ c - $ b * $ b ) / ( 2 * $ a * $ c ) ) ; return $ B * 180 / $ PI ; } function printAngles ( $ a , $ b , $ c ) { $ x = ( double ) $ a ; $ y = ( double ) $ b ; $ z = ( double ) $ c ; $ A = findAnglesA ( $ x , $ y , $ z ) ; $ B = findAnglesB ( $ x , $ y , $ z ) ; echo " Angles ▁ are ▁ A ▁ = ▁ " . $ A . " , B = " ▁ . ▁ $ B ▁ . ▁ " , C = 90 " ; } function printOtherSides ( $ n ) { if ( $ n & 1 ) { if ( $ n == 1 ) echo " - 1 STRNEWLINE " ; else { $ b = ( $ n * $ n - 1 ) / 2 ; $ c = ( $ n * $ n + 1 ) / 2 ; echo " Side ▁ b ▁ = ▁ " . $ b . " , ▁ Side ▁ c ▁ = ▁ " . $ c . " STRNEWLINE " ; } } else { if ( $ n == 2 ) echo " - 1 STRNEWLINE " ; else { $ b = $ n * $ n / 4 - 1 ; $ c = $ n * $ n / 4 + 1 ; echo " Side ▁ b ▁ = ▁ " . $ b . " , ▁ Side ▁ c ▁ = ▁ " . $ c . " STRNEWLINE " ; } } printAngles ( $ n , $ b , $ c ) ; } $ a = 12 ; printOtherSides ( $ a ) ; ? >