i've been sitting here for 2 hours searching through info sites
and forums getting absolutely nothing out of it. its a simple
problem i have. how to add fractions in c:
where a/b + c/d == x/y
can someone point me in the right direction?
i've been sitting here for 2 hours searching through info sites
and forums getting absolutely nothing out of it. its a simple
problem i have. how to add fractions in c:
where a/b + c/d == x/y
can someone point me in the right direction?
You treat fractions as ordered pairs of integers, and reduce them to lowest terms if they aren't already, using the Euclidean algorithm
http://en.wikipedia.org/wiki/Euclidean_algorithm
to compute the GCD of the numerator and denominator and then divide both by it. In the case of adding fractions, use the formula
a/b + c/d == (ad + bc)/bd
followed by reduction to lowest terms as described above.
You better try again: That formula does not work for the following two fractions of adding 1/3 and 1/5. According to the formula above, this would be equivalent to 3/5, whereas the real answer is 8/15. Or is my arithmetic that bad??
Yes, your arithmetic is bad (1 * 5 + 1 * 3)/(3 * 5) == 8 / 15
If you tried it programmatically then a / b * c != a / (b * c) although the parenthesis should not be required by human conventions (multiplication has higher precedence in algebraic notation?)
Last edited by anon; 01-10-2008 at 12:13 PM.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
mea culpa!!