Objective: Find the Angle between hour hand and minute hand at the given time.

Example:

Time : 12:45
Input : hour = 12, Minute = 45
Output : 112.5
Time : 3:30
Input : hour = 3, Minute = 30
Output : 75
Approach:

At 12:00 both hand meet, take it as reference.
Angle between hand and minute = angle of hour hand ~ angle of minute hand.
return minimum(angle, 360-angle)
hour hand moves 360 in 12 hours => 360/12 = 30 degree in one hour or 0.5 degree in 1 min
Minute hand moves 360 in 60 mins => 360/60 = 6 degree in one min
So if given time is h hours and m mins, hour hand will move (h*60+m)*0.5 and minute hand will move 6*m
Code: Run This Code

Run This Code
Output :

112.5
75.0
66.5
__________________________________________________
Top Companies Interview Questions..-

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.
__________________________________________________

Like this: Like Loading...