Solved

# fractions part2

Posted on 1998-11-01
285 Views
Last Modified: 2010-04-02
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
Question by:strmtrpr
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
3 Comments

LVL 84

Expert Comment

ID: 1176769
gcd(a*c,b*d)
0

LVL 22

Accepted Solution

nietod earned 50 total points
ID: 1176770
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

Author Comment

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

Thank you for your help.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
###### Suggested Courses
Course of the Month6 days, 15 hours left to enroll

#### 732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.