Thread: fibonacci number help

  1. #1
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278

    fibonacci number help

    i want to evaluate fibonacci numbers using the Closed form expression given in wiki

    http://upload.wikimedia.org/math/9/6...9a765ce708.png

    i tried using this...

    Code:
    double result;
    
    result =  ( pow(GOLDEN_RATIO,n) - pow(1-GOLDEN_RATIO,n) ) /sqrt(5);
    printf("%f \n", result);
    but its not working! what shall i do?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    How did you #define GOLDEN_RATIO?

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    You will need to round the result the the nearest integer. Floating point has finite precision, and may not give 100% precise results.
    Last edited by King Mir; 08-24-2009 at 07:50 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 09:27 AM
  2. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  3. Finding a number within a number
    By jeev2005 in forum C Programming
    Replies: 2
    Last Post: 01-10-2006, 08:57 PM
  4. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  5. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 01:10 PM