Link to home
Start Free TrialLog in
Avatar of strmtrpr
strmtrpr

asked on

fractions

I have a recursive funtion that is supposed to
factor out the greatest common denominator.
long gcd(long x, long)
{
  return (x ==0L) ? y : gcd()y % x, x);
}
this works fine. I put two denominators in I get a number out
here is the question.
how I am I supposed to use this to add fraction.
if I put a 3,5 in I get a 1 out.
this is a silly question, I must be looking at this
at the wrong angle.
Please help.
Avatar of strmtrpr
strmtrpr

ASKER

that is supposed to be gcd(y % x, x);
sorry.
that is supposed to be gcd(y % x, x);
sorry.
ASKER CERTIFIED SOLUTION
Avatar of newexpert
newexpert

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 ozo
a/b + c/d = (a*d+b*c)/(b*d) = ((a*d+b*c)/gcd(b,d)) / (b*d/gcd(b,d))
I told you it was a silly question.

thanks for the help