一个程序来检查数字是否与斐波那契数列相关 [英] a program to check if the number is related to fibonacci series or not

查看:128
本文介绍了一个程序来检查数字是否与斐波那契数列相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以通过找到一种方式帮助我
如何纠正程序以检查数字是否属于斐波那契数列
而不计算整个斐波那契数????


斐波那契数列的数学代码是
f(x)= f(x-1)+ f(x-2)x> = 2

计数代码很简单,但是我需要检查用户输入的数字!

但是,如果内存不是必需的,而您希望您的应用程序可重复使用.
我建议选择一种简化的动态编程方法

1)保留动态数组[]
2)每当给出输入时,都在Array中进行二进制搜索
3)如果找到,请跳至步骤5
4)如果未找到,则计算序列,直到获得从数组N-1和第N个元素开始的斐波那契数,并将结果添加到数组
5)将响应发送给用户

这将使您的程序更快,并且输入列表将提高性能.


最好的问候,
Raina


在Wikipedia中进行了描述:
http://en.wikipedia.org/wiki/Fibonacci_number [



要求用户输入数字并将其存储在变量中.在循环中,
开始使用您的公式逐个生成斐波那契数,然后将每个数与用户输入进行比较,如果与用户输入相同,则相应地显示消息.
如果不相同,则生成该系列的下一个编号,然后继续进行直到匹配为止.
这是基本的逻辑流程.希望您可以对此进行改进并自己编写代码.

祝您编码愉快!


can any one help me by finding a way
how to right a program to check whether the number belongs to fibonacci series
without counting the whole fibonacci numbers?????


fibonacci series math code is
f(x)=f(x-1)+f(x-2) x>=2

the counting code is easy but i need to check a number entered by user!!!!

解决方案

As suggested by Resmi the mathemaical approach is the best for your question.

However, if memory is not a constaint and you want your application for repetitive use.
I suggest go for a simplified approach of Dynamic programming

1)Keep a Dynamic Array []
2)Whenver input is given do a binary search in Array
3) if found , jump to step 5
4)If not found compute the series till you get the Fibonacci number starting from N-1 and Nth element in the Array and add the result to Array
5) send the response to user

This will make your program much faster and performance will increase with the input list.


Best Regards,
Raina


That''s described in wikipedia:
http://en.wikipedia.org/wiki/Fibonacci_number[^], chapter "Recognizing Fibonacci numbers".


hi,
ask the user to input a number, store that in a variable.In a loop,
start generating fibonacci number one by one using your formula and compare each number with users input, if this is same as users input,then display mesage accordingly.
if its NOT same,then generate next number of the series and go on till you get a match.
this is a basic logic flow.I hope you can improve on this and code yourself.

happy coding !!


这篇关于一个程序来检查数字是否与斐波那契数列相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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