## Microsoft Interview Question for Software Engineer in Tests

Comment hidden because of low score. Click to expand.
3
of 0 vote

float returnangle(int hour, int min )
{
float hourAngle = (360/12 ) *(hour+min/60);
float minAngle = 360/60*min;
float angle = hourAngle - minAngle;
return ( angle >0 )? angle:-angle;
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

can you explain this?

Comment hidden because of low score. Click to expand.
0
of 0 vote

It 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.

Comment hidden because of low score. Click to expand.
0
of 0 vote

func(int hour, int min){

if (hour > 12) hour = hour-12 ;

hourangle = hour * 360/12 ;
minangle = min*360/60 ;
int angle = minangle - hourangle ;

if(angle >0) return angle ;
else return(360+angle);
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>

int main()
{
float hr, min, angle;

printf ("\n enter hr - ");
scanf ("%f",&hr);

printf ("\n enter min - ");
scanf ("%f",&min);

angle = 30 * hr - (5.5) * min ;

printf ("\nangle - %f\n",angle);

return 0;
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

hours hand also drifts = 30 deg/hour/60 = .5 deg/min
gotta add this to angle moved by hour hand...

Comment hidden because of low score. Click to expand.
0
of 0 vote

return Math.Abs((hour % 12) * (360 / 12) + ((minute % 60) * 30 / 60) - (minute % 60 * 360 / 60));

Comment hidden because of low score. Click to expand.
0
of 0 vote

return abs((hour%12)*(30+0.5)-min*6

Comment hidden because of low score. Click to expand.
0
of 0 vote

return abs((hour%12)*(30+0.5)-min*6)

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.