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; }
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);
}
Nice catch Payal.