# 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.
###### Who is Participating?

x

Commented:
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
0

Author Commented:
that is supposed to be gcd(y % x, x);
sorry.
0

Author Commented:
that is supposed to be gcd(y % x, x);
sorry.
0

Commented:
a/b + c/d = (a*d+b*c)/(b*d) = ((a*d+b*c)/gcd(b,d)) / (b*d/gcd(b,d))
0

Author Commented:
I told you it was a silly question.

thanks for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.