Home > Back-end >  Enter two positive integers m and n, strives for the least common multiple, and the greatest common
Enter two positive integers m and n, strives for the least common multiple, and the greatest common

Time:09-19

# include
Void main ()
{
Int m (int x, int y);
Int a, b, t, p, q;
Printf (" please enter the two positive integers: ");
The scanf (" % d, % d ", & amp; P, & amp; Q);
If (p==q)
{
Printf (" the greatest common divisor and least common multiple of: % d \ n ", p);
}
Else if (p{
t=p;
P=q;
Q=t;
A=m (p, q);
B=p * q/a; Printf (" the greatest common divisor is: % d \ n ", a);
Printf (" LCM is: % d \ n ", b);
}
The else
{
A=m (p, q);//same as above
B=p * q/a;
Printf (" the greatest common divisor is: % d \ n ", a);
Printf (" LCM is: % d \ n ", b);
}
}
# include
Int m (int x, int y)
{
Int z;
While (y!=0)
{
Z=x % y;
x=y;
Y=z;
}
Return (x);
}
/* */explain the first ten lines of the following procedures at thank you!!!!!!

CodePudding user response:

Division algorithm, beginners if you don't understand this can temporarily, or search the blog see the mathematical principles,

CodePudding user response:

N=qm + r (Euclidean algorithm)

CodePudding user response:

The GCD (m, n) is the principle of division and out of use
  • Related