Thread: Fractions in fibonacci series

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    5

    Fractions in fibonacci series

    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?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    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.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    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??

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    mea culpa!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fibonacci prime
    By dbzx in forum C Programming
    Replies: 5
    Last Post: 04-17-2009, 11:13 AM
  2. fibonacci using recursion?
    By n3cr0_l0rd in forum C Programming
    Replies: 12
    Last Post: 02-25-2009, 08:49 AM
  3. Recursive Fibonacci, some help needed
    By cwafavre in forum C Programming
    Replies: 8
    Last Post: 11-04-2007, 02:20 PM
  4. Fibonacci series using recursion
    By IPCHU in forum C Programming
    Replies: 1
    Last Post: 12-07-2006, 06:05 AM
  5. Fibonacci series using a recursive function
    By Dargoth in forum C++ Programming
    Replies: 3
    Last Post: 02-05-2002, 12:54 AM