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

 

orion.a.smith@gmail.com apcsa-loops > apcsaLoopsWhichFib
prev  |  next  |  chance

Given an input num, return which number in the Fibonacci sequence is equal to or greater than num. The Fibonacci sequence is f(0) = 0, f(1) = 1, f(n) = f(n - 1) + f(n - 2). Computing Fibonacci is quite simple using a while loop and a few variables; the only additional chore here is figuring out when to stop based not on how many numbers to print (which is the usual Fibonacci programming problem), but when you have reached a certain value. Precondition: num > 3.


HINT: update the variables in a sequence.  Also, what kind of loop do you need when you don't know how many Fibonacci numbers to go through?

apcsaLoopsWhichFib(4) → 5
apcsaLoopsWhichFib(5) → 5
apcsaLoopsWhichFib(6) → 6

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

public int apcsaLoopsWhichFib(int num) { }

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: 210

Copyright Nick Parlante 2017 - privacy