ksdf.net
当前位置:首页>>关于求fibonacci数列前40个数, 这个数列有如下特点, 第...的资料>>

求fibonacci数列前40个数, 这个数列有如下特点, 第...

#include void main() { int i; static int f[20]={1,1}; for(i=2;i

由Fi= Fi-1+Fi-2 (i>=3)可得特征方程: x^2=x+1 解得特征根x=2分之1加减根号5 设Fi= A(2分之1加根号5)^i+B(2分之1减根号5)^i 将F0,F1代入,得A+B=0 A(2分之1加根号5)+B(2分之1减根号5)=1 所以A=1/根号5,B=-1/根号5 Fi=(1/根号5)(2分之1加根号5...

Private Sub Form_Load()Dim I As IntegerForm1.AutoRedraw = TrueFor I = 1 To 40Print Fibonacci(I);Next IEnd SubPrivate Function Fibonacci(ByVal N As Integer) As LongDim F(32767) As LongIf N = 1 Or N = 2 Then Fibonacci = 1Else Fib...

按Fibonacci数列规则,它的第一项是0,第二项是1。从第三项开始,当前项是前两项之和,即数列结构是:0,1,1,2,3,5,8...。可以自定义一个函数求各项之值(为提高时效,不用递归),代码如下: //#include "stdafx.h"//If the vc++6.0, with t...

Dim a() As Long Dim i As Long Dim n As Long n = Val(InputBox("请输入n:")) ReDim a(n - 1) a(0) = 0 a(1) = 1 Print a(0); Print a(1); For i = 2 To n - 1 a(i) = a(i - 2) + a(i - 1) Print a(i); If i Mod 5 = 4 Then Print Next

#include int fib(int n){ if(n == 0 || n== 1) return 1; else return fib(n - 1) + fib(n - 2);}int main(int argc, char const *argv[]){ int i = 0, k; while(i < 40) { printf("%d ", fib(i)); if(i%3 == 2) printf("\n"); ++ i; } return 0;}

C语言,用for循环,求Fibonacci数列前40个数的程序如下: #include int main(void){ int a=1,b=1,t=0; printf("%d,",a); printf("%d,",b); for(int i=0;i

用循环效率高,用迭代也能实现

求Fibonacci数列:1,1,2,3,5,8,… …的前40个数 #include #include int f(int n); main() { int i,a[40]; for(i=1;i

CLEARSET TALK OFFinput [n=] to nf1=1f2=1FOR i=1 to ndo case CASE i=1 or i=2? i,f1OTHERWISE f3=f1+f2? i,f3f1=f2f2=f3ENDCASE NEXT iRETURN

网站首页 | 网站地图
All rights reserved Powered by www.ksdf.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com