The following code calculates the maximum common divisor and least common multiple of two positive integers, m and n:
# Include <stdio. h>
Void main ()
{
Int m, n, gcd, lcm;/gcd is the maximum common approx. lcm is the least common multiple/
Int max, min, swap;/max is m, n is smaller than min, n is smaller/
Printf ("input two positive integers m and n ");
Scanf ("% d", & m, & n );
Max = m> n? M: n;/returns m. n is greater than limit to max/
Min = m <n? M: n;/return m. The smaller value in n is min/
Swap = min;/obtain the value when the value of swap is smaller than that of swap/
If (max % min = 0)
{
Gcd = min;
Printf ("maximum common approx. gcd = % d", gcd );
}
While (swap! = 0)
{
Swap = swap-1;/find a smaller value/
If (max % swap = 0 & min % swap = 0)
{
Gcd = swap;
Printf ("maximum common approx. gcd = % d", gcd );
Break;/find the stop loop/
}
}
Lcm = m * n/gcd;
Printf ("minimum public factor lcm = % d", lcm );
}