Friday, July 16, 2010

Finding the Greatest Common Divisor

It is Euclid's method on finding the GCD. Although there are several applications for this algorithm, finding the GCD of two numbers is the most famous one.
 int findGreatestCommonValue(unsigned int m, unsigned int n) {   if( (m == 0) || (n == 0) )     throw exception();    //Ensure that m is greater than n   //otherwise swap them   if(m < temp =" n;" n =" m;" m =" temp;" remainder =" m" m =" n;" n =" remainder;" remainder =" m">

No comments:

Post a Comment