Calculate the angle between hour hand and minute hand | Utility function to find minimum of two integers ; Function to calculate the angle ; validate the input ; Calculate the angles moved by hour and minute hands with reference to 12 : 00 ; Find the difference between two angles ; Return the smaller angle of two possible angles ; Driver Code
< ? php function mintwo ( $ x , $ y ) { return ( $ x < $ y ) ? $ x : $ y ; } function calcAngle ( $ h , $ m ) { if ( $ h < 0 $ m < 0 $ h > 12 $ m > 60 ) echo " Wrong ▁ input " ; if ( $ h == 12 ) $ h = 0 ; if ( $ m == 60 ) { $ m = 0 ; $ h += 1 ; if ( $ h > 12 ) $ h = $ h - 12 ; } $ hour_angle = 0.5 * ( $ h * 60 + $ m ) ; $ minute_angle = 6 * $ m ; $ angle = abs ( $ hour_angle - $ minute_angle ) ; $ angle = min ( 360 - $ angle , $ angle ) ; return $ angle ; } echo calcAngle ( 9 , 60 ) , " STRNEWLINE " ; echo calcAngle ( 3 , 30 ) , " STRNEWLINE " ; ? >