The classical algorithm for greatest common divisor and least common multiple is described as follows:
If greatest common divisor and least common multiple are required for a, a, two number, A is a, B is the larger number, B is the smaller number, the algorithm further process:
while (b is not 0)
{
Temp=a%b;
A=b;
B=temp
}
Finally a is the greatest common divisor of two number, the maximum common multiple is: a*b/greatest common divisor
C Language code:
on.intDivisor (intAintb/*greatest common divisor of two numbers for custom functions*/ Geneva. { Geneva.intTemp/*Defining integer Variables*/ Geneva.if(A<B)/*find the maximum and minimum values in two numbers by comparison*/ to. { .. temp=A; -. A=b; ,. b=temp; the. }/*set intermediate variables to exchange two numbers*/ Ten. while(b!=0)/*the remainder of two numbers is calculated by looping until the remainder is 0*/ One. { A. temp=a%b; -. A=b;/*Variable Value Exchange*/ -. b=temp; the. } -.returnA/*returns greatest common divisor to the calling function*/ -.} -. +. -.intMultiple (intAintb/*least common multiple of two numbers for custom functions*/ +. { A.inttemp; at. Temp=divisor (A, b);/*call the Custom function to find out the greatest common divisor*/ -.return(a*b/temp);/*returns least common multiple to the keynote function for output*/ -.}
Poke here
Divide and seek greatest common divisor! or least common multiple