欢迎来到天天文库
浏览记录
ID:50336542
大小:48.50 KB
页数:5页
时间:2020-03-08
《程序设计基础——Visual Basic学习与实验指导 教学课件 作者 陈丽芳习题答案 第10章实验答案.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、实验10-2:PrivateSubCommand1_Click()DimyAsIntegerFori=0To2IfOption1(i)=TrueTheny=Val(Option1(i).Caption)EndIfNextCallcalc(y)EndSubPrivateSubcalc(yAsInteger)ClearListi=1x=Val(Text1.Text)+1DoWhilei<=5IfxMody=0ThenList1.AddItemxi=i+1EndIfx=x+1LoopEndSubPrivateSubClearList()Fork=List1.Li
2、stCount-1To0Step-1List1.RemoveItemkNextkEndSub实验10-3:PrivateSubCommand1_Click()DimmAsIntegerDimnAsInteger,iAsInteger,sAsLongm=Val(Text1.Text)n=Val(Text2.Text)s=0Fori=mTont=f(i)s=s+tNextlblresult.Caption=sEndSubPrivateFunctionf(ByRefxAsInteger)AsLongDimtAsLongt=1Fori=1Toxt=t*iNextf
3、=tEndFunction实验10-4:在窗体模块中PrivateSubForm_Click()DimmAsInteger,nAsIntegerCallf(Val(Text1(0).Text),Val(Text1(1)),Val(Text1(2)),m)Callf(Val(Text1(3)),Val(Text1(4)),Val(Text1(5)),n)Ifm>nThenText2=mElseText2=nEndSub在标准模块中PublicSubf(aAsInteger,bAsInteger,cAsInteger,xAsInteger)Ifa>bThenx
4、=aElsex=bIfx5、.AddItempNextpEndSub实验10-8-1:Functionfib(nAsInteger)AsIntegerIfn=1Orn=2Thenfib=1Elsefib=fib(n-1)+fib(n-2)EndIfEndFunctionPrivateSubCommand1_Click()DimmAsInteger,iAsIntegerm=InputBox("请输入项数:")Fori=1TomList1.AddItemfib(i)NextiEndSub实验10-8-2:Functionfxn(x!,n%)AsSingleIfn<0Thenfxn=fxn6、(x,n+1)/xElseIfn=0Thenfxn=1Elsefxn=x*fxn(x,n-1)EndIfEndFunctionPrivateSubCommand1_Click()DimxAsSingle,nAsIntegerx=Val(Text1)n=Val(Text2)Text3=fxn(x,n)EndSub实验10-9:Functionproc1(nAsInteger)AsLongDimiAsInteger,fAsLongf=1Fori=1Tonf=f*iNextiproc1=fEndFunctionPrivateSubCommand1_Click()7、DimiAsInteger,sumAsSinglei=1:n=1Dot=i/proc1(i+1)sum=sum+(-1)^(n+1)*ti=i+2n=n+1LoopUntilAbs(t)<10^(-6)Print"前";n;"项的和为:";sumEndSub实验10-10:Subqg(aAsSingle,bAsSingle,cAsSingle,x1AsSingle,x2AsSingle)x1=-b+Sqr(b*b-4*a*c)/(2*a)x2=-b-Sqr(b*b-4*a*c)/(2*a)EndSubPrivateSubCommand1_Click()Di8、maAsSingle,bAsSingle,cAsSingleDim
5、.AddItempNextpEndSub实验10-8-1:Functionfib(nAsInteger)AsIntegerIfn=1Orn=2Thenfib=1Elsefib=fib(n-1)+fib(n-2)EndIfEndFunctionPrivateSubCommand1_Click()DimmAsInteger,iAsIntegerm=InputBox("请输入项数:")Fori=1TomList1.AddItemfib(i)NextiEndSub实验10-8-2:Functionfxn(x!,n%)AsSingleIfn<0Thenfxn=fxn
6、(x,n+1)/xElseIfn=0Thenfxn=1Elsefxn=x*fxn(x,n-1)EndIfEndFunctionPrivateSubCommand1_Click()DimxAsSingle,nAsIntegerx=Val(Text1)n=Val(Text2)Text3=fxn(x,n)EndSub实验10-9:Functionproc1(nAsInteger)AsLongDimiAsInteger,fAsLongf=1Fori=1Tonf=f*iNextiproc1=fEndFunctionPrivateSubCommand1_Click()
7、DimiAsInteger,sumAsSinglei=1:n=1Dot=i/proc1(i+1)sum=sum+(-1)^(n+1)*ti=i+2n=n+1LoopUntilAbs(t)<10^(-6)Print"前";n;"项的和为:";sumEndSub实验10-10:Subqg(aAsSingle,bAsSingle,cAsSingle,x1AsSingle,x2AsSingle)x1=-b+Sqr(b*b-4*a*c)/(2*a)x2=-b-Sqr(b*b-4*a*c)/(2*a)EndSubPrivateSubCommand1_Click()Di
8、maAsSingle,bAsSingle,cAsSingleDim
此文档下载收益归作者所有