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.
You can do it exactly as you do fraction addition by hand.
a/b + c/d = ( a*d + b*c ) / (b*d)
Now the result is not the simplest form. We can reduce it to the simplest form by dividing both top and bottom by their gcd.
Therefore
a/b + c/d = (A/gcd(A, B)) / (B/gcd(A, B)) where A = a*d + b*c and B = b*d
sorry.