Solved

fractions part2

Posted on 1998-11-01
3
281 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
Comment
Question by:strmtrpr
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1176769
gcd(a*c,b*d)
0
 
LVL 22

Accepted Solution

by:
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

by:strmtrpr
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now