资源描述:
《中国海洋大学vb上机试题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1.某数组有20个元素,其值为随机产生的两位整数。现要求将前10个元素与后10个元素对换。即第1个元素与第20个元素互换,第2个数与第19个元素互换,…,第10个元素与第11个元素互换。在窗体上输出数组原来各元素的值与对换后各元素的值。OptionExplicitDima(1To20)AsInteger,iAsInteger,jAsInteger,tAsIntegerPrivateSubForm_Load()me.ShowPrint"原始数组是:"RandomizeFori=1To20a(i)=Int(Rnd*90+10)'10to99Printa(i
2、);IfiMod10=0ThenPrintNextiPrintPrint"现在数组是:"Fori=1To10j=21-it=a(i):a(i)=a(j):a(j)=tNextiFori=1To20Printa(i);IfiMod10=0ThenPrintNextiEndSub2.从数组中删除一个数。先定义一个一维数组,大小、数组的值自定。从键盘上输入一个数,若这个数在数组当中,就把它删除;若这个数不在数组中,提示“该数不在数组中”注意:1)如果数组中存在多个与该数相同的元素,每一个都能删除;2)能实现多次删除Dima()AsIntegerPrivate
3、SubCommand1_Click()DimiAsInteger,jAsInteger,nAsInteger,kAsInteger,mAsInteger,flagAsBooleann=InputBox("查找的数是:")i=0:flag=FalseDoIfa(i)=nThenj=i:flag=TrueFork=jToUBound(a)-1a(k)=a(k+1)NextkReDimPreservea(UBound(a)-1)i=i-1he"governingforthepeople","Nomattertheinterestsofthemasses"co
4、nceptunderstandingisnotinplace.Thespecificworktreatswiththedeployment,afewleadingcadrescomplainthatworkistoocomplicated,toomuchresponsibility,thepressureistoolarge,toomuchemphasisonthedifficultyofthework.Forexample,noncoalmine15EndIfi=i+1LoopWhile(i<=UBound(a))Ifflag=FalseThenMs
5、gBox(n&"不在该数组中")ElsePrint"删除"&n&"后的数组是:"Fori=0ToUBound(a)Printa(i);NextiEndIfEndSubPrivateSubForm_Load()DimiAsIntegerReDima(9)AsIntegerShowRandomizePrint"原来数组为:"Fori=0To9a(i)=Int(Rnd*99+1)Printa(i);NextiPrintEndSub3.数组a中存放着升序排列的数据,使用array赋值,将inputbox输入的新数插入到数组中,插入后数组仍有序。注意:要求利用动
6、态数组,能够实现多次插入OptionBase1Dima()AsInteger,iAsInteger,kAsInteger,mAsInteger,nAsIntegerPrivateSubCommand1_Click()Print"随机产生的原数组:"ReDimPreservea(10)n=10Fori=1TonRandomizea(i)=Int(Rnd*99+1)NextFori=1Ton-1Forj=i+1TonIfa(i)>a(j)Thent=a(i):a(i)=a(j):a(j)=the"governingforthepeople","Nomatt
7、ertheinterestsofthemasses"conceptunderstandingisnotinplace.Thespecificworktreatswiththedeployment,afewleadingcadrescomplainthatworkistoocomplicated,toomuchresponsibility,thepressureistoolarge,toomuchemphasisonthedifficultyofthework.Forexample,noncoalmine15EndIfNextjPrinta(i);Nex
8、tiPrinta(n)EndSubPrivateSubCommand2_Click()n=n+