In the Fibonacci sequence, is fib(0) 0 or 1 ?

前端 未结 10 1803
南旧
南旧 2020-12-14 15:11

I\'m doing a task in a subject were fib(0) is defined to = 1. But that can\'t be right? fib(0) is 0?

Program with fib(0) = 1; spits out fib(4) = 5
Program w         


        
10条回答
  •  一向
    一向 (楼主)
    2020-12-14 15:32

    Fibonacci series doesn't start with 0. It starts with 1.
    We are getting confused trying to represent a mathematical concept as a computer program. The term "Fib(0)" is the array index that holds the first Fibonacci number which is always 1. We are asking this question because we have to return something from the program when someone enters 0 as input. What that input essentially means is to generate 0 Fibonacci numbers. So you return a message saying "No Fibonacci numbers generated"

提交回复
热议问题