Find GCD of Two Numbers

Ques: Problem: To find GCD of two number.

Solution:

#include

using namespace std;
int gcd_iter(int u, int v)
{
int t;
while (v)
{
t = u;
u = v;
v = t % v;
}
return u < 0 ? -u : u;
}
int main()
{
int n=3,m=6;
int result=gcd_iter(n,m);
cout<<result;
return 0;
}

Please do comment the code in other languages :).

5 comments on “Find GCD of Two Numbers”