Solved

fractions

Posted on 1998-10-27
5
297 Views
Last Modified: 2010-04-02
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.
0
Comment
Question by:strmtrpr
  • 3
5 Comments
 

Author Comment

by:strmtrpr
ID: 1176374
that is supposed to be gcd(y % x, x);
sorry.
0
 

Author Comment

by:strmtrpr
ID: 1176375
that is supposed to be gcd(y % x, x);
sorry.
0
 
LVL 1

Accepted Solution

by:
newexpert earned 50 total points
ID: 1176376
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
 
LVL 84

Expert Comment

by:ozo
ID: 1176377
a/b + c/d = (a*d+b*c)/(b*d) = ((a*d+b*c)/gcd(b,d)) / (b*d/gcd(b,d))
0
 

Author Comment

by:strmtrpr
ID: 1176378
I told you it was a silly question.

thanks for the help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

757 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

22 Experts available now in Live!

Get 1:1 Help Now