id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

gaurav.gupta@mq.edu.au recursion > fibonacci
prev  |  next  |  chance

Fibonacci sequence and Fibonacci numbers are extremely famous. The sequence begins with 0, 1 and each subsequent number is the sum of the two numbers before it. Thus fib(0) = 0, fib(1) = 1, fib(n) = fib(n-1) + fib(n-2).

Define a function that when passed an integer, returns the Fibonacci number at that index.

Note: the difficulty is in solving this problem such that you DON'T call the function two times (during each call).

You will most likely need to add a helper function.


fibonacci(0) → 0
fibonacci(10) → 55
fibonacci(20) → 6765

...Save, Compile, Run (ctrl-enter)

int fibonacci(int n) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 4 Post-solution available

Copyright Nick Parlante 2017 - privacy