How to simplify a fraction

user379888 picture user379888 · Oct 15, 2011 · Viewed 39.3k times · Source

I want to simplify a fraction in my application. The fraction is like, x/y where x and y are integers. I want to simplify the fraction to its simplest form. Can anyone please give me hints how to do it. Thanks in advance.

Answer

cnicutar picture cnicutar · Oct 15, 2011
  • Compute the greatest common divisor for x and y
  • Divide both of them by the GCD

Euclid's algorithm is an easy way to compute the GCD.