Fibonacci sequence: Difference between revisions
Content deleted Content added
Logo |
add E example |
||
Line 143: | Line 143: | ||
I : 99194853094755497 <- 61305790721611591 + 37889062373143906 |
I : 99194853094755497 <- 61305790721611591 + 37889062373143906 |
||
O : 99194853094755497 <- 61305790721611591 + 37889062373143906</pre> |
O : 99194853094755497 <- 61305790721611591 + 37889062373143906</pre> |
||
=={{header|E}}== |
|||
def fib(n) { |
|||
var s := [0, 1] |
|||
for _ in 0..!n { |
|||
def [a, b] := s |
|||
s := [b, a+b] |
|||
} |
|||
return s[0] |
|||
} |
|||
(This version defines <code>fib(0) = 0</code> because [http://www.research.att.com/~njas/sequences/A000045 OEIS A000045] does.) |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |