Problem: To find GCD of two number.


Solution:

#include <iostream>

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

For AMCAT Programming – Coding Questions Visit our AMCAT Previous Coding Dashboard