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;
}
No comments:
Post a Comment