vb求菲波那契数列的前40项
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/10 19:17:56
添加一个文本框输入前N项的N值,再添加一个命令按钮即可PrivateFunctionF(NAsLong)AsLongIfN>2ThenF=F(N-1)+F(N-2)ElseF=1EndIfEndFun
为用了很没有效率的递归,所以出结果有点慢#includeiostream.h
267914295,用EXCEL很简单的
DimnAsIntegerDimmAsIntegerDimiAsIntegerDimjAsIntegerDima(30)AsInteger'确定数组的范围()里的数即为最大可储存数+1PrivateS
OptionExplicitDimf(40)AsLongPrivateSubCommand1_Click()DimiAsByteDimsAsLongf(1)=1f(2)=1s=2Print"No1:"
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
PrivateFunctionF(nAsLong)AsLongIfn>2ThenF=F(n-1)+F(n-2)ElseF=1EndIfEndFunctionPrivateSubCommand1_Cli
OptionExplicitDimFileNameAsString'文件名变量PrivateSubForm_Load()DimFilePathAsStringFilePath=App.PathIfRi
VB程序斐波那契数列代码ma,b,ciasintegera=1b=1fori=3to10c=aba=bb=cdebug.printcnexti
斐波那契数列的发明者,是意大利数学家列昂纳多·斐波那契.斐波那契数列指的是这样一个数列:1、1、2、3、5、8、13、21、……下面是前1000项斐波那契数列的和的VB代码:PrivateSubCom
PrivateFunctionbq(ByValsAsLong)AsLongSelectCasesCase1bq=1Case2bq=1CaseIs>=3bq=bq(s-1)+bq(s-2)EndSele
OptionExplicit'产生斐波那契数列并保存到D:\fb.txtPrivateSubCommand1_Click()DimFB(1To15)AsIntegerDimiAsInteger'产生斐
/>'第一题privatesubcommand1_click()dimf(1to20)asintegerf(1)=1f(2)=1printf(1);f(2);fori=3to20f(i)=f(i-1)
PrivateSubForm_Load()Rem在这里定义一个inti来控制数字的循环变化,定义intNumber是用来输入要求第几个数Diminti,intNumberAsInteger'lngFi
Private Sub Command1_Click()Dim F(11), i As LongF(0) = 
1123581321345589143232375607……
Private Sub Form_Load()Dim I As IntegerForm1.AutoRedraw = TrueFor
PrivateFunctionbq(ByValsAsLong)AsLongSelectCasesCase1bq=1Case2bq=1CaseIs>=3bq=bq(s-1)+bq(s-2)EndSele
'计算按钮事件编辑框名默认Dimarr(),rd()AsInteger'定义存放数列的数组Dimi,a,b,n,sumAsIntegera=1b=1n=Val(Text1.Text)'输入求数列的项数
先写两个数列.PublicSubaa()DimabAsStringDimi,jAsIntegerDima,bAsInteger'素数序列Fori=1To1000Forj=1ToiIfiModj=0An