Link to home
Start Free TrialLog in
Avatar of strmtrpr
strmtrpr

asked on

fractions part2

I have this recursive function again.
long gcd (long x, long y)
{
   return (x==0L) ? y : gcd( y % x,x);
}
this is supposed to keep fractions in the lowest terms.
it works fine for addition and subtraction
how can I use it for multiplication and division.
I have always multiplied fractions like this
a/b *c/d = a *c / b*d
how can I use the gcd to reduce
thanks in advance.
Avatar of ozo
ozo
Flag of United States of America image

gcd(a*c,b*d)
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of strmtrpr
strmtrpr

ASKER

that did it , I had the right idea I just messed up my syntax  a little.

Thank you for your help.