## Microsoft Interview Question

Software Engineer in TestsIt is correct and very simple math logic.

For 12 hours, the hours needle rotates 360 degrees.

For 1 hours, it rotates 360/12 = 30 degrees.

For 1 hour, the minutes needle rotates 360 degrees.

For 1 minute, it rotates 360/60 = 60 degrees.

Hence the corresponding positions are represented by minAngle and hourAngle.

And then they are subtracted and absolute value is taken.

Conclusion - 12 hour clock as 2:00 clock returns 60.

Ofcourse, there are some cases to be considered. What if the input is 23:20.

hourAngle = (360/12)*((hour%12)+min/60);

We can reduce a variable.

return (hourangle>minangle)? hourangle - minangle: minangle - hourangle;

We can still remove more variables but it is not worth the try for readability issues.

float returnangle(int hour, int min )

- amit August 20, 2008{

float hourAngle = (360/12 ) *(hour+min/60);

float minAngle = 360/60*min;

float angle = hourAngle - minAngle;

return ( angle >0 )? angle:-angle;

}