Results 1 to 2 of 2

Math Help - fibonnaci code

  1. #1
    xxxGxxx
    Guest

    Unhappy fibonnaci code

    HEY GUYS, please help me out, i am trying to do some programming and im stuck now. i need to implement an iterative funtion in python so i can generate numbers in the fibonacci sequence. below is the the coding for it.

    fib(0) = 1
    fib(1) = 1
    fib(n) = fib(n − 1) + fib(n − 2)

    please can someone help me on how to implement it.

    appreciate it if anyone could,

    Thanks.

    G X
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by xxxGxxx View Post
    HEY GUYS, please help me out, i am trying to do some programming and im stuck now. i need to implement an iterative funtion in python so i can generate numbers in the fibonacci sequence. below is the the coding for it.

    fib(0) = 1
    fib(1) = 1
    fib(n) = fib(n − 1) + fib(n − 2)

    please can someone help me on how to implement it.

    appreciate it if anyone could,

    Thanks.



    G X
    Well I don't know Python but here it is in Euler:

    Code:
    function fibb(n)
      if n==1 
        return 1;
      elseif n==0
        return 1
      endif
    
      rv=fibb(n-1)+fibb(n-2);
    
      return rv
    endfunction
    and some example calls:

    Code:
    >
    >fibb(1)
                1 
    >fibb(0)
                1 
    >fibb(2)
                2 
    >fibb(3)
                3 
    >fibb(4)
                5 
    >fibb(15)
              987 
    >
    RonL
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Code
    Posted in the Algebra Forum
    Replies: 1
    Last Post: October 9th 2011, 01:08 AM
  2. Real Analysis: Fibonnaci Numbers 2
    Posted in the Differential Geometry Forum
    Replies: 1
    Last Post: February 28th 2010, 11:38 AM
  3. Fibonnaci numbers
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: October 1st 2009, 02:12 AM
  4. fibonnaci - inequality
    Posted in the Discrete Math Forum
    Replies: 8
    Last Post: April 1st 2009, 12:41 PM
  5. C++ code?
    Posted in the Math Software Forum
    Replies: 7
    Last Post: August 19th 2008, 02:05 PM

Search Tags


/mathhelpforum @mathhelpforum