斐波那契系列 [英] Fibonacci Series

查看:115
本文介绍了斐波那契系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要帮助解决这个问题。我已经尝试过编写程序,我只是无法让它正常运行。


请写下

斐波那契系列

0,1,1,2,3,5,8,13,21,......

以0和1开头,并且具有每个后续项是两者之和的属性前面的条款。

(a)写一个非递归函数fibonacci(n)来计算第n个Fibonacci数。


而不是你

解决方案

这是一个非常简单的循环实现,你应该自己去,然后我们如果您的解决方案出现问题,将会有所帮助。


您还可以通过几分钟的网络搜索找到一个公式。然而,它使用无理数上的浮点计算,因此可能不完全适合计算机(浮点计算不精确)。


有一个简单的递归关系,这将有助于。


斐波那契(n)=斐波那契(n-1)+斐波那契(n-2)。这是递归关系,它是递归的,但很容易实现为循环。


//非递归方法

展开 | 选择 | Wrap | 行号

hi
I need help with this problem. I have tried writting the program, i just can not get it to run properly.

Please Write
The Fibonacci series
0, 1, 1, 2, 3, 5, 8, 13, 21, ...
begins with the terms 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms.
(a) Write a nonrecursive function fibonacci( n ) that calculates the nth Fibonacci number.

and than you

解决方案

This is very simply achieved with a loop, you should have a go yourself and then we will help if there are problems in your solution.

There is a formula as well which you should be able to find with a few minutes web search. However it uses the floating point calculations on an irrational number so may not be entirely suited to a computer (where floating point calculations are not exact).


There is a simple recurrence relation which will help.

fibonacci(n) = fibonacci(n-1) + fibonacci(n-2). That''s the recurrence relation which is recursive, but it is easily implemented as a loop.


//Non recursive method

Expand|Select|Wrap|Line Numbers


这篇关于斐波那契系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆