您的位置:首页 >我爱生活 >

Fibonacci数列中,第4个和第11个数分别是

导读 大家好,今天小六子来为大家解答以下的问题,关于Fibonacci数列中,第4个和第11个数分别是这个很多人还不知道,现在让我们一起来看看吧!1、

大家好,今天小六子来为大家解答以下的问题,关于Fibonacci数列中,第4个和第11个数分别是这个很多人还不知道,现在让我们一起来看看吧!

1、你看下下面的程序是否得到你要的结果,有问题可以留言。

2、 #include unsigned int fib(unsigned int num) { if( num == 0 ) return 0; /* num should not be zero. */ if(num==1 || num==2) { return 1; } else { return fib(num-1)+fib(num-2); } } int main( int argc, char** argv ) { int m = 0; int n = 0; int i = 0; int result; while( m<1 || n>10000 ) { printf("Input m( m >= 1 ) :"); scanf("%d",&m); printf("Input n( n <= 10000 ):"); scanf("%d",&n); } for( i=1;1;i++ ) { result = fib(i); if( result < m ) { continue; /* test the next */ } else if( result > n ) { break; /* end test */ } else { printf("%d ", result); /* print the fibonacci number */ } } getch(); return 0; }。

本文分享完毕,希望对你有所帮助。

免责声明:本文由用户上传,如有侵权请联系删除!