Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

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.
0
strmtrpr
Asked:
strmtrpr
1 Solution
 
ozoCommented:
gcd(a*c,b*d)
0
 
nietodCommented:
Once you have your result

(a*c)/(b*d)

use GCD to find the greatest common factor of  the numerator and the denominator, that is

GCD(a*c,b*d)

Then divide the numerator and denumenator by this GCD value.  Let me know if you have questions.


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

Thank you for your help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now