Algorithm of 579 - ClockHands

Problem Description Link

This is a calculation of the angle between the minute hand and the hour hand on a regular analog clock.
To solve this problem you can follow this stapes:
1. Get input hour and minute.
2. For hour 1 to 11 the angle of hour hand = hour*30+min*.5;
    because between two hour angle is 30
    e.x.
         when hour hand goes from 1 to 2 then hour hand move 30 degree angle so each hour hour hand angel is 30 and for each minute hour angle is move .5 degree.
3. For each minute, minute hand angle is 6 degree
      so minute hand angle = min*6
4. If hour is 12 then hour hand angle =hour*0+min*.5; and minute hand angle=min*6;

  N.B:  Each angle measured from 12 hour position angle must between 0 to 180.

5. Final angle is absolute value of difference between hour hand and minute hand.
6. if difference is greater than 180 then this angle deduct from 360.
7. so you get final angle between hour hand and minute hand.
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience