Microsoft Interview Question for Software Engineer / Developers






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

int GCD(int a, int b)
{
if(a == 0)
return b;
while (b != 0)
{
if(a > b)
a = a - b;
else
b = b - a;
}
return a;
}

- dronzer709 May 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

int gcd(int a, int b)
	{
			  if(b==a) return a;
			  if (a>b)
				  return gcd(a-b, b);
			  else
				  return gcd(a, b-a);
	}

- rajarshi129 September 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is M and N....?

- jproboy July 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess M=U, N=V.. though it looks a little strange...

- ashek1520 July 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Euclid algo. Whether this was asked during an interview? I don't believe ...

- AL July 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is euclid algo

- nitin July 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int getGCD(int u, int v){

int x ,y;

if(u < v){
x=u; y= v;
}
else{
x=v; y=u;
}
while(x!=0){

u= x;
x=y%x;
y=u;
}

return u;
}

- Anonymous July 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int gcd(int a, int b)
{
  if(b==0) return a;
  return gcd(b, a%b);
}

- Anonymous July 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is a totally wrong code bro...

- rockstar September 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

see wiki also this is correct algo en.wikipedia.org/wiki/Euclidean_algorithm

- Aspire September 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>
#include<math.h>
using namespace std;
int main(void)
{
int a,b,c,d,temp=0,rem=0;
cout<<"Enter the two nos\n";
cin>>a>>b;
c=a<b?a:b;
d=a>b?a:b;
while(rem!=0){
rem=d%c;
d=c;
c=rem;
}
cout<<c;
cin.get();
}

- Baurisetty Dhiraj August 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it must be cout<<d;

- Anonymous August 21, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

euclid's algo is the right ans dude...

- rockstar September 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this can be done using binary GCD algorithm (steins alg)

- logeshwari February 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
int num1, num2;
int div, rem,quot;
printf("\n Enter number 1 : \n");
scanf("%d",&num1);
printf("\n Enter number 2 : \n");
scanf("%d",&num2);

if(num1<num2)
{
quot=num1;
div=num2;
}
else
{
quot=num2;
div=num1;
}
rem=num1+num2;

while(rem)
{
rem=div%quot;
if(rem!=0)
{
div=quot;
quot=rem;
}
}
printf("\n GCF is <%d> \n",quot);
}

- Kunal Bansal September 09, 2014 | 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