Nth Fibonacci Number

RECURSION

Problem

Given n, calculate the nth number in the Fibonacci sequence.

The Fibonacci sequence is characterized by the fact that every number after the first two is the sum of the two preceding ones, and starts with 0 and 1.

Examples

fib(0) // returns 0 fib(1) // returns 1 fib(2) // returns 1 fib(6) // returns 8 fib(10) // returns 55
Loading...