x = 122 && Read Numerator
Y = 990 && Read Denominator
*!* g = 1
*!* Display the given fraction
Messagebox("Original Fraction: " + Transform(x) + " / " + Transform(Y))
*!* Calculate GCD
g = gcd(x, Y)
*!* Reduce the fraction
X = X / g
Y = Y / g
*!* Display result
Messagebox("Reduced Fraction: " + Transform(x) + " / " + Transform(Y))
*!***************************************
*!* Name: GCD - Reduce a Fraction
*!* Description:The proper way to reduce a fraction to simplest terms. (For example, 12/32 reduces to 3/8) Divide both the numerator and the denominator by the
greatest common divisor of the numerator and denominator. Most programmers are familiar with this GCD algorithm. If this is new to you, take a moment to understand
what this does and how it can be used. It comes in handy!
*!* By: korejwa
*!*
*!*This code is copyrighted and has&& limited warranties.Please see http://www.
details.&&**************************************
Function gcd(X, Y )
gcd = 0
If X < 0
X = -x && Euclid's Algorithm
Endif
If Y < 0
Y = -Y && Returns Greatest Common Divisor of x and y
Endif
If X = 0 Or Y = 0
? "Math Error in GCD" &&If both x and y are zero ...
Endif
gcd = Y
Do While X > 0
gcd = X
x = Y % X
Y = gcd
Enddo
Return gcd
Endfunc