The method used below is called the division of the moving phase. The steps are as follows:
First use a small number to divide a large number and obtain the first remainder;
Use the first remainder to divide a small number and obtain the second remainder;
The second remainder is used to divide the first remainder, and the third remainder is obtained;
In this way, the remainder is removed from the last one until the remainder is 0. In this case, the last divisor is the maximum common divisor (if the last divisor is 1, the original two divisor is the mutual prime number ).
C language:
# Include <stdio. h>
Main ()
{
Int P, R, n, m, temp;
Printf ("enter two positive integers n, m"); // note when running this place. Cut them apart.
Scanf ("% d, % d", & N, & M );
P = N * m;
If (n <m)
{Temp = N;
N = m;
M = temp;
}
While (M! = 0)
{
R = n % m;
N = m;
M = R;
}
Printf ("their maximum common divisor: % d/N", N );
Printf ("their minimum public multiples are: % d/N", P/N );
}
In C ++:
# Include "iostream. H"
Void main ()
{
Int n, m, temp, R, J;
Cout <"Please input n = ";
Cin> N;
Cout <"Please input m = ";
Cin> m;
J = m * N;
If (n <m)
{
Temp = N;
N = m;
M = temp;
}
While (M! = 0)
{
R = n % m;
N = m;
M = R;
}
Cout <"their maximum common approx. is:" <n <Endl;
Cout <"their minimum public multiples are:" <j/n <Endl;
}