Rational Numbers Reduce Function

Hey guys, I know what needs to be done but I cant figure out how to write the code...

n = numerator;
d = denominator;

If the numerator > denominator then do n mod d....if result does not equal 0 then reduce d by 1...once result = 0 take the result and do numerator mod d and do denominator mod d...if denominator mod d does not equal 0 then reduce d again by 1 until both numerator and denominator equals 0....once both equal 0 return d as the greatest common divisor...


Last edited on
That's euclidean algorithm. there is some pseudocode. http://en.wikipedia.org/wiki/Euclidean_algorithm#Implementations
Topic archived. No new replies allowed.