## Microsoft Interview Question for Software Engineer / Developers

• 0

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

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

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

what is M and N....?

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

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

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

what is euclid algo

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

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

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

this is a totally wrong code bro...

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

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

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

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

it must be cout<<d;

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

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

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

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

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

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.