Find the angle between hour handle and minute handle

Given the time in 24 hour format.Find the angle between hour handle and minute handle in a clock at any given time.

Solution : Visualize the clock as a 360 degree circle.As we know that Hour handle completes 360 degree in 12 hours.In 1 hour or 60 minutes it complete 360/12 i.e. 30 degree.Minute handle completes 360 degree in 60 minutes.In 1 minutes it completes 360/60 i.e. 6 degree.

double calculateAngle(int hh,int mm)
{

double hAngle = (hh%12+mm/60)*30;
double mAngle = mm*6;
double angle = ans(mAngle-hAngle);
angle = min(angle, 360 - angle);
return angle;
}

2 Thoughts on “Find the angle between hour handle and minute handle

  1. Payal Chauhan on August 16, 2014 at 1:48 pm said:

    whatif the input is not valid.. like value of hh or mm is less than zero , or since we are taking 12hour as a standard so hh> 12 and minutes mm>60 is INVALID.

    if( mm< 0 || hh<0 || mm>60 || hh>12)
    {
    printf("INVALID INPUT"n);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation