Can anyone help me with coding the GCD? I want to take two integers 56 and 42 and divide them x amount of times until the remainder is 0. Once the remainder is 0 that divisor becomes my GCD.
Gcd
Collapse
X
-
So your code should be directly translatable to pseudocode. Did you try working this out by habd? What if n is less than n (ie, the numbers are reversed)? I think you should put more thought into your algorithm before you start coding.Originally posted by AmLegacyint my_gcd (int *m, int *n)
{
while (m > 0)
{
if (n > m)
{ int t = m; m = n; n = t; }
m -= n;
}
}Comment
Comment