If you are given 2 number U and V then Write a program....
Microsoft Interview Questions and Answers
(Continued from previous question...)
61. If you are given 2 number U and V then Write a program....
Question:
If you are given 2 number U ≈ V then Write a program to find the GCD of the numbers. complexity of the program shoud be of the order {(log MN)^2 }.
maybe an answer1:
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;
}
maybe an answer2:
#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();
}
(Continued on next question...)
Other Interview Questions
|