两个数字之间的斐波那契数列
#include<iostream>
int* fib(int);
int main()
{
int count;
std::cout<<"enter number upto which fibonacci series is to be printed"<<std::endl;
std::cin>>count;
int *p=new int[count];
p=fib(count);
int i;
for(i<0;i<=count;i++)
std::cout<<p[i]<<std::endl;
return 0;
}
int* fib(int d)
{
int *ar=new int[d];
int p=-1,q=1,r;
int j;
for(j=0;j<=d;j++)
{
r=p+q;
ar[j]=r;
p=q;
q=r;
}
return ar;
delete ar;
}
该程序正在打印系列中给定计数的斐波那契系列。请分享一些想法,我如何转换该程序以查找两个数字之间的斐波那契系列。
#include<iostream>
int* fib(int);
int main()
{
int count;
std::cout<<"enter number upto which fibonacci series is to be printed"<<std::endl;
std::cin>>count;
int *p=new int[count];
p=fib(count);
int i;
for(i<0;i<=count;i++)
std::cout<<p[i]<<std::endl;
return 0;
}
int* fib(int d)
{
int *ar=new int[d];
int p=-1,q=1,r;
int j;
for(j=0;j<=d;j++)
{
r=p+q;
ar[j]=r;
p=q;
q=r;
}
return ar;
delete ar;
}
this program is printing fibonacci series with given count in the series.please share some idea that how can i convert this program to find fibonacci series between two numbers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果给定 N >= 0 的
(5*N*N + 4)
或(5*N*N - 4)
是完全平方数,则该数字为斐波那契。使用此方法生成两个数字之间的斐波那契数列。If
(5*N*N + 4)
or(5*N*N - 4)
for a given N >= 0 is a perfect square then the number is Fibonacci. Employ this method to generate Fibonacci series between two numbers.