欢迎来到天天文库
浏览记录
ID:48208107
大小:81.00 KB
页数:24页
时间:2020-01-22
《VB常用算法代码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.Feb数列前18项OptionBase1PrivateSubForm_Click()DimFeb(18)AsInteger,IAsIntegerFeb(1)=1Feb(2)=1ForI=3To18Feb(I)=Feb(I-1)+Feb(I-2)NextForI=1To18PrintFeb(I),IfIMod5=0ThenPrintNextEndSub鞍点OptionExplicitOptionBase1PrivateSubForm_Click()ClsDimA(4,5)AsInteger,IAsInteger,JAsInteger,KAsIntege
2、rDimMaxAsInteger,MinAsIntegerDimRowAsInteger,ColAsInteger,FlagAsBooleanRandomizeForI=1To4ForJ=1To5A(I,J)=Rnd*90+10PrintA(I,J);NextPrintNextI=1Flag=FalseDoWhileI<=4Max=A(I,1)Row=ICol=1ForJ=2To5IfMaxA(K,Col)ThenI=I+1F
3、lag=FalseExitForEndIfNextIfK=5ThenFlag=TrueExitDoEndIfLoopIfNotFlagThenPrint"鞍点不存在!"ElsePrint"鞍点的位置:"&CStr(Row)&"行"&CStr(Col)&"列"EndSub插入排序OptionBase1PrivateSubCommand1_Click()DimA(10)AsInteger,IAsInteger,JAsInteger,XAsIntegerClsPrint"排序前:";ForI=1To10A(I)=Int(100*Rnd)PrintA(I);N
4、extPrintForJ=2To10X=A(J)I=J-1DoWhileX5、tA(I);NextPrintDimFirstAsInteger,LastAsInteger,MiddleAsIntegerDimKAsIntegerForJ=2To10X=A(J)First=1Last=J-1DoWhileFirst<=LastMiddle=(First+Last)/2IfX>A(Middle)ThenLast=Middle-1ElseFirst=Middle+1EndIfLoopForK=J-1ToMiddleStep-1A(K+1)=A(K)NextA(Middle)=XNextPrint"排序后:";ForI=1To10Pri6、ntA(I);NextEndSub插入一个数到有序数列DimA(10)AsInteger,IAsInteger,JAsIntegerPrivateSubCommand1_Click()DimXAsInteger..X=Text1.TextI=9DoWhileX7、nd)NextForI=0To8ForJ=I+1To9IfA(I)>A(J)Thentemp=A(I)A(I)=A(J)A(J)=tempEndIfNextNextPrint"有序序列:";ForI=0To9PrintA(I);NextPrintText1.SetFocusEndSubPrivateSubForm_Activate()Print"将一个数插入到一个有序的序列中!"EndSub查找子串位置OptionBase1..PrivateSubCommand1_Click()DimS1AsString,S2AsStringS1=Text1.Text8、S2=Text2.TextText3.Text=Index(S1,S2)EndSubPubli
5、tA(I);NextPrintDimFirstAsInteger,LastAsInteger,MiddleAsIntegerDimKAsIntegerForJ=2To10X=A(J)First=1Last=J-1DoWhileFirst<=LastMiddle=(First+Last)/2IfX>A(Middle)ThenLast=Middle-1ElseFirst=Middle+1EndIfLoopForK=J-1ToMiddleStep-1A(K+1)=A(K)NextA(Middle)=XNextPrint"排序后:";ForI=1To10Pri
6、ntA(I);NextEndSub插入一个数到有序数列DimA(10)AsInteger,IAsInteger,JAsIntegerPrivateSubCommand1_Click()DimXAsInteger..X=Text1.TextI=9DoWhileX7、nd)NextForI=0To8ForJ=I+1To9IfA(I)>A(J)Thentemp=A(I)A(I)=A(J)A(J)=tempEndIfNextNextPrint"有序序列:";ForI=0To9PrintA(I);NextPrintText1.SetFocusEndSubPrivateSubForm_Activate()Print"将一个数插入到一个有序的序列中!"EndSub查找子串位置OptionBase1..PrivateSubCommand1_Click()DimS1AsString,S2AsStringS1=Text1.Text8、S2=Text2.TextText3.Text=Index(S1,S2)EndSubPubli
7、nd)NextForI=0To8ForJ=I+1To9IfA(I)>A(J)Thentemp=A(I)A(I)=A(J)A(J)=tempEndIfNextNextPrint"有序序列:";ForI=0To9PrintA(I);NextPrintText1.SetFocusEndSubPrivateSubForm_Activate()Print"将一个数插入到一个有序的序列中!"EndSub查找子串位置OptionBase1..PrivateSubCommand1_Click()DimS1AsString,S2AsStringS1=Text1.Text
8、S2=Text2.TextText3.Text=Index(S1,S2)EndSubPubli
此文档下载收益归作者所有