Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Clock Angle Problem

Objec­tive: Find the Angle between hour hand and minute hand at the given time.

Exam­ple:

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:


Out­put:

112.5
75.0
66.5

You may also like...