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 along the series ; Holds the actual value of sin ( n ) ; Function to find third side ; Driver Code ; function call
< ? php function cal_cos ( $ n ) { $ accuracy = 0.0001 ; $ x1 ; $ denominator ; $ cosx ; $ cosval ; $ n = $ n * ( 3.142 / 180.0 ) ; $ x1 = 1 ; $ cosx = $ x1 ; $ cosval = cos ( $ n ) ; $ i = 1 ; do { $ denominator = 2 * $ i * ( 2 * $ i - 1 ) ; $ x1 = - $ x1 * $ n * $ n / $ denominator ; $ cosx = $ cosx + $ x1 ; $ i = $ i + 1 ; } while ( $ accuracy <= ( $ cosval - $ cosx ) ) ; return $ cosx ; } function third_side ( $ a , $ b , $ c ) { $ angle = cal_cos ( $ c ) ; return sqrt ( ( $ a * $ a ) + ( $ b * $ b ) - 2 * $ a * $ b * $ angle ) ; } $ c = 49 ; $ a = 5 ; $ b = 8 ; echo third_side ( $ a , $ b , $ c ) ; ? >