Fibonacci numbers, commonly denoted Fn, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,
and
The beginning of the sequence is thus
Given a number N, caculate the Nth Fibonacci number.
数据结构和算法:初级练习题 #7 – 斐波那契数列
斐波那契数列指的是这样一个数列:0、1、1、2、3、5、8、13、21、34、……在数学上,斐波那契数列以如下被以递推的方法定义:F(0)=0,F(1)=1, F(n)=F(n – 1)+F(n – 2)。这个数列从第3项开始,每一项都等于前两项之和。
给定一个数字N,计算斐波那契数列第N个数字。