The Fibonacci sequence is a sequence    Fn    of natural numbers defined recursively:

      F0 = 0 
      F1 = 1 
      Fn = Fn-1 + Fn-2, if n>1 



Task

Write a function to generate the    nth    Fibonacci number.

Solutions can be iterative or recursive (though recursive solutions are generally considered too slow and are mostly used as an exercise in recursion).

The sequence is sometimes extended into negative numbers by using a straightforward inverse of the positive definition:

      Fn = Fn+2 - Fn+1, if n<0   

support for negative      n      in the solution is optional.



Related tasks

   Fibonacci n-step number sequences‎
   Leonardo numbers


References

   Wikipedia, Fibonacci number
   Wikipedia, Lucas number
   MathWorld, Fibonacci Number
   Some identities for r-Fibonacci numbers
   OEIS Fibonacci numbers
   OEIS Lucas numbers


;
;       Fibonacci sequence for DBL version 4 by Dario B.
;
        RECORD
 
FIB1,  D10
FIB2,  D10
FIBN,  D10
 
J,     D5
A2,    A2
A5,    A5
                                PROC
;----------------------------------------------------------------
        XCALL FLAGS (0007000000,1)         ;Suppress STOP message
 
        OPEN (1,O,'TT:')
        DISPLAY (1,'First 10 Fibonacci Numbers:',10)
 
        FIB2=1
 
        FOR J=1 UNTIL 10
        DO BEGIN
                FIBN=FIB1+FIB2
 
                A2=J,'ZX'
                A5=FIBN,'ZZZZX'
                DISPLAY (1,A2,' : ',A5,10)
 
                FIB1=FIB2
                FIB2=FIBN
            END
 
        CLOSE 1
END