资源描述:
《经典vb编程题》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.Fibonacci函数。PrivateSubCommand1_Click()DimnAsIntegern=Text1Text2=fib(n)EndSubFunctionfib(ByValxAsInteger)AsIntegerIfx=1Orx=2Thenfib=1Elsefib=fib(x-2)+fib(x-1)EndIfEndFunctionPrivateSubCommand2_Click()Text1=""Text2=""Text1.SetFocusEndSubPrivateSubCommand3_Click()EndEndSub2.
2、百元百鸡PrivateSubcmdCalc_Click()'变量说明DimxAsIntegerDimyAsIntegerDimzAsInteger'穷举法计算Forx=1To20Fory=1To33z=100-x-yIf5*x+3*y+z/3=100ThenText1=Text1&CStr(x)&Space(6)&CStr(y)&Space(6)&CStr(z)&Chr(13)&Chr(10)EndIfNextyNextxEndSub3.矩阵不靠边元素和Forj=1To5a(i,j)=Int(Rnd*90)+10NextNextFori=1T
3、o5Forj=1To5Picture1.Printa(i,j);NextPicture1.PrintNextEndSubPrivateSubCommand2_Click()Text1=fun1(a)EndSubFunctionfun1(x()AsInteger)AsDoubleDimiAsInteger,jAsIntegerfun1=0Fori=LBound(x,1)ToUBound(x,1)Forj=LBound(x,2)ToUBound(x,2)IfNot(i=LBound(x,1)Ori=UBound(x,1)Orj=LBound(x,
4、2)Orj=UBound(x,2))Thenfun1=fun1+x(i,j)EndIfNextNextEndFunctionPrivateSubCommand3_Click()Text1=""Picture1.ClsCommand1.SetFocusEndSubPrivateSubCommand4_Click()EndEndSub4.递归函数PrivateSubCommand1_Click()List1.ClearDimiAsIntegerFori=1To7List1.AddItemfact(i)NextiEndSubFunctionfact
5、(ByValnAsDouble)AsDoubleIfn=1Thenfact=1Elsefact=n*fact(n-1)EndIfEndFunctionPrivateSubCommand2_Click()List1.ClearEndSubPrivateSubCommand3_Click()EndEndSub5.回文数PrivateSubCommand1_Click()RandomizeDimiAsInteger,xAsInteger,minAsIntegerFori=1To500x=Int(Rnd*9000)+1000Text1=Text1&x
6、&vbCrLfIfHuiWenShu(x)ThenText2=Text2&x&vbCrLfIfmin=0Thenmin=xElseIfmin>xThenmin=xEndIfEndIfEndIfNextiText3=minEndSubFunctionHuiWenShu(ByValaAsInteger)AsBooleanIfStrReverse(a)=aThenHuiWenShu=TrueElseHuiWenShu=FalseEndIfEndFunctionPrivateSubCommand2_Click()Text1=""Text2=""Tex
7、t3=""EndSubPrivateSubCommand3_Click()EndEndSub6.级数求和。PrivateSubCommand1_Click()DimsAsDouble,nAsLongDimmAsDoubles=0n=1Dom=1/(2*n-1)Ifm<10^(-5)ThenExitDos=s+mn=n+1LoopText1=CStr(s)EndSubPrivateSubCommand2_Click()Text1=""EndSubPrivateSubCommand3_Click()EndEndSub7.矩阵转置OptionBas
8、e1Dima(4,4)AsIntegerPrivateSubCommand1_Click()DimbAsInteger,cAsIntegerDimiAsIntege