Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Exercise: Fibonacci Series

Sumit Rawal answered on May 16, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • fibonacci series
  • fibonacci series
  • fibonacci series
  • fibonacci series
  • fibbonacci series
  • fibonacci series
  • Efficient Fibonnaci numbers
  • Efficient Fibonnaci numbers
  • Fibonacci series
  • fibonacci series
  • Solution Review: Fibonacci Series
  • Fibonacci series

  • Exercise: Fibonacci Series

    0

    Fibonacci sequence is a series of numbers where every number is the sum of the two numbers before it. The first two numbers are 0 and 1:

    0 1 1 2 3 5 8 13

    You must write the fib() function which takes in a positive integer, n, and returns the n-th Fibonacci number. However, instead of using recursion, your function must use any of the loops.

    Sample Input

    n = 7

    Sample Output

    8

    Coding Challenge

    Take some time to figure out how the recursive approach can be translated into an iterative one. Consider all edge cases that could occur.

    If n is negative or zero, return -1.

    If you feel stuck, feel free to refer to the solution review in the next lesson. 

    Popularity 1/10 Helpfulness 1/10 Language python
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 16 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.