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;
}

- amit August 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can you explain this?

- byte.man September 07, 2008 | Flag Reply
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.

- Anbe September 16, 2008 | Flag Reply
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);
}

- Anonymous October 12, 2008 | Flag Reply
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;
}

- Sarz November 07, 2008 | Flag Reply
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...

- Anonymous March 08, 2009 | Flag Reply
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));

- Anonymous August 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Anonymous December 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Anonymous December 09, 2009 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More