Use the Euclidean theorem to obtain the maximum common number and the least common number.
function gcd(a,b){return b == 0 ? a : gcd(b,a%b);}function lcm(a,b){return a * b / gcd(a,b);}console.log(gcd(24,42));console.log(lcm(16,36));
Description of the maximum common divisor and least common multiple of two numbers programmed in C language: the maximum of the two positive integers using the moving phase division (that is, the Euclidean Algorithm)
# Include <stdio. h>
Void main ()
{
Int a, B, c, d, div, rem; // a, B is the input number
Scanf ("% d", & a, & B );
If (a <B)
{
C =;
A = B;
B = c;
}
D = a * B; // The product of input numbers a and B
Div = B;
While (a % div! = 0)
{
C = a % B;
A = div;
Div = c;
}
Rem = d/div;
Printf ("% d \ n", rem );
}
In C language, use the function to call the maximum public approx. And the minimum public multiple
# Include <stdio. h>
Int main ()
{
Int m, n;
Int f (int m, int n );
Printf ("please input two numbles :");
Scanf ("% d", & m, & n); // note the input format. You have added ','.
Printf ("the max is % d \ n", f (m, n ));
Printf ("the min is % d \ n", m * n/f (m, n ));
Return 0;
}
Int f (int m, int n)
{
Int c;
C = m % n;
While (c! = 0)
{
M = n;
N = c;
C = m % n;
}
Return (n );
} // Learn to debug simple programs