求斐波那契数列的前20项
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/10 10:54:11
为用了很没有效率的递归,所以出结果有点慢#includeiostream.h
PrivateFunctionF(nAsLong)AsLongIfn>2ThenF=F(n-1)+F(n-2)ElseF=1EndIfEndFunctionPrivateSubCommand1_Cli
dima()aslong,nasintegern=inputbox("请输入n的值:")redima(1ton)callFibonaccia()subFibonacci(a()aslong)dimia
intnum=1;intprev=0;for(inti=0;i
267914295,用EXCEL很简单的
#include#defineCOL5//一行输出5个longfibonacci(intn){//fibonacci函数的递归函数if(0==n||1==n){//fibonacci函数递归的出口re
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121
#include#includevoidsolve(){inti;inta[100],n=20;//保存数列,可以更改大小a[0]=0;a[1]=1;for(i=2;i再问:这个运行结果对着没再答:对
PrivateFunctionbq(ByValsAsLong)AsLongSelectCasesCase1bq=1Case2bq=1CaseIs>=3bq=bq(s-1)+bq(s-2)EndSele
#includevoidmain(){inta[21];a[0]=0;a[1]=1;for(inti=2;i
这样写已经可以实现了,可以编译后执行一下就知道了,不过格式不太规范啊
Private Sub Command1_Click()Dim F(11), i As LongF(0) = 
1123581321345589143232375607……
方法1:斐波那数列前30项是1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,4
#!/bin/bash#fibo.sh:Fibonaccisequence(recursive)#Author:M.Cooper#License:GPL3######----------algorit
若前3项是0,1,1的话,前20项的和=10946若前3项是1,1,2的话,前20项的和=17711怎么会有小数的呢?再问:哦,我说错了,是2/1,3/2,5/3,8/5,13/8等等以此类推,不好意
1123581321345589144就是新的项前两个连续项相加
PrivateFunctionbq(ByValsAsLong)AsLongSelectCasesCase1bq=1Case2bq=1CaseIs>=3bq=bq(s-1)+bq(s-2)EndSele
#includea,stdio>main(){intn,i=1,j,a;scanf("%d",&n);for(i=1,i