《VB:课后习题(全部答案).pdf》由会员分享,可在线阅读,更多相关《VB:课后习题(全部答案).pdf(60页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、第一章1、B2、A3、B4、答:属性:红色、充满氢气;事件:松手、针刺;方法:飞走、爆破。5、答:事件是指对象能够识别并作出反映的外部刺激。事件驱动又称消息驱动,事件驱动程序设计是指每个事件对应有相应的程序代码,仅在该事件发生时,该段代码才会被执行。事件发生的顺序决定了代码执行的顺序,因此每次执行应用程序时,程序代码并不是按照程序编写的顺序来执行的。6、答:V B 是一个包括界面设计、程序编码、调试、编译并创建可执行程序的集成开发环境。V B 的集成开发环境的主界面中包含:标题栏、菜单栏、工具栏、控件箱、工程资源管理器、属性窗口、“窗体布局”窗口、窗体设计器、代码编辑器等元素组成。7、答:V
2、B 菜单条通常情况下有:文件、编辑、视图、工程、格式、调试、运行、查询、图表、工具、外接程序、窗口、帮助等1 3 项菜单项组成。8、答:工具栏可自行定义。标准工具栏中通常情况下有:添加标准e x e 工程、添加窗体、菜单编辑器、打开工程、保存工9、答:创 建 V B 应用程序的一般步骤为:创建界面;设置窗体和控件属性;编写代码;保存工程;运行并调试程序;检查并排除错误;创建可执行文件。1 0、P r i v at e S u b C o m m an d l _ C l i c k()L ab e l 1.C ap t i o n =I l o v e v b,I h at e v b”E n
3、 d S u b第二章1、2、结束3、S 1 输入待判断自然数:N (N =2);S 2 i=2;S3判断i 是否小于NT,若不是转S 5S4判断N除以i 的余数是否为0,如果不是则i=i+l 转 S 3;S5判 断 i是否等于N,若是输出“是素数”,否则输出“不是素数”。4、S 1 输入待判断自然数:N;S2将 N 转换成字符S,计算S的长度K;S 3 i=l;S4判断i 是否小于KT,若不是转S 6;S5判断S中的第i 位和第K-i+1 位是否相等,如果是则i=i+l转 S 4,如果不是则转S 6;S6判断i 是否是中间位数,若是输出“是回文数”,否则输出“不是回文数”。5、S 1 输入待
4、判断自然数:a;S 2 i=l;S3判断i 是否小于a-1,若不是转S 5S4判断a 除以i的余数是否为0,如果是则保留因子i,否则i=i+l 转 S 3;S5输出所有因子。6、第三章1、窗体的属性主要分为杂项、外观、行为、字体、位置等五类。C a p ti o n 是窗体标题,出现在窗体标题栏的文本内容;而N a m e 是窗体名称,在程序代码中被作为窗体的标识名。2、A B D E4、改变窗口的工作状态会引发A c ti va te 事件,改变窗口大小会引发re si z e 事件。5、f o re c o l o r和 b a c k c o l o r属性首先选择系统中的选项,然后在调
5、色板中设置相应的颜色;f o n t属性设置好以后,在窗体上放置的任何控件都会继承窗体的f o n t属性。6、C7、L a b e l、o p ti o n b utto n、c h e c k b o x、c o m m a n d b utto n 有c a p ti o n 属性,没有 te xt 属 性;te xt、c o m b o b o x 有 te xt 属性,没有c a p ti o n 属性8、对象的属性可以在设计界面时在属性窗口中和运行中在代码中设置;属性窗口中的属性列表并没有包括对象的所有属性。9、p i c ture b o x、f ra m e 等1 0、o p
6、ti o n b utto n 和 c h e c k b o xo O p ti o n b o x 的 V a l ue 可以取true 一选中和f a l se 一未选中,c h e c k b o x的V a l ue 可以取0 未选中,1 一选中,2 变灰,表示暂时不能访问。1 1、te xt、c o m m a n d b utto n 可以获得焦点。在设计界面时第一个放在窗体上的文本框或命令按钮将得到焦点。1 2、C1 3、把 V a l ue 的值设为2,表示暂时不能访问复选框,点击复选框后就可以访问了,而 把 e n a b l e d 属性设为f a l se 则是复选框变
7、灰,完全不能访问。若把一个控件的V i si b l e 属性设为f a l se则在程序运行时看不到该控件。1 4、用 a d d i te m 来添加列表项,用 re m o ve i te m 删除已有的列表项,用 c l e a r删除所有列表项。1 5、16、Private Sub Checkl_Click()If Checkl.Value=1 ThenLabel2.Font.Italic=TrueElself Checkl.Value=0 ThenLabel2.Font.Italic=FalseEnd IfEnd SubPrivate Sub Check2_Click()If Ch
8、eck2.Value=1 ThenLabe12.Font.B old=TrueElself Check2.Value=0 ThenL a b e l 2.F o n t.B o l d =F a l seE n d I fE n d SubPri va te Sub C o m m a n d 1 _ C l i c k()E n dE n d SubPri va te Sub O p ti o n l _ C l i c k()I f O p ti o n l.V a l ue Th e n L a b e l 2.F o n t.Si z e =1 2L a b e 1 2.Re f re
9、 shE n d SubPri va te Sub 0 p ti o n 2 _ C l i c k()I f 0 p ti o n 2.V a l ue Th e n L a b e 1 2.F o n t.Si z e =1 4L a b e l 2.Re f re shE n d SubPri va te Sub 0 p ti o n 3 _ C l i c k()I f 0 p ti o n 3.V a l ue Th e n L a b e 1 2.F o n t.Si z e =1 6L a b e l 2.Re f re shE n d SubPri va te Sub 0 p
10、ti o n 4 _ C l i c k()I f 0 p ti o n 4.V a l ue Th e n L a b e 1 2.F o n t.N a m e =宋体L a b e l 2.Re f re shE n d SubPri va te Sub 0 p ti o n 5 _ C l i c k()I f 0 p ti o n 5.V a l ue Th e n L a b e 1 2.F o n t.N a m e =隶书L a b e 1 2.Re f re shE n d SubPri va te Sub 0 p ti o n 6 _ C l i c k()I f 0 p
11、ti o n 6.V a l ue Th e n L a b e l 2.F o n t.N a m e =黑体L a b e 1 2.Re f re shE n d Sub1 7、录单编每wIS回 冈标题名称索引帚助上下文ID厂复选 广有效确定取消快捷键|Ctrl+S 3防调位.置|0-None 三 可见 显示窗口列表下一个|插入 删除18、第四章1.B2.见教材P4 0-4 13.不对,通用过程也可以存在于窗体模块中4 .见教材P4 35.字符串型常量的界定符是双引号,日期型数据的界定符是磅号丸A、B是字符型,C、D是日期型,E、F 不属于任何类型。6.合法变量名有:A、C、D (V B
12、中合法变量名只能由字母、数字和下划线构成,并且只能以字母开头)7.见教材P4 68.(1)a/(b+c/d)(2)(sqr(x2+l)+x)(1/3)(3)(2*y)/(a*x+b*y)*(a*x-b*y)(4)1+1/(1+1/m)(d/3)2*x)/2(6)log(y+cos(x)2)(7)fabs(exp(x)+sin(x)3)/(x+y)(8)log(exp(x*y)+fabs(tan(z)-1+cos(x)3)/(x+y-z)9.(1)(2)(A+B)/(A-B)(3)(4)A*B*C/(D+1)*Y)(5)(6)(X*Y)10.A x+y0B x*y0 and x=fix(x)an
13、d y=fix(y)C A=0 XOR B=0D Cl+C2+C3=255 and Cl90 and C290 and C38011.T F F F F12.B CD E(A会发生溢出的错误)13.(1)“354 8(2)354 8(3)“354 8”(4)354 8(5)83 (6)83(7)354 8(8)354 81 4.以2 为底的X 的对数:log(x)/log(2)15.C16.z=Inputbox(输入一个数:”,程序示例,1.5)17.Msgbox Z的值1.5大于0,4 8,程序示例”18.Option ExplicitConst PI As Single=3.14 159P
14、rivate Sub Commandl_Click()D im a As Single,b As Single,c As Single,areaAs Singlea=Vai(Textl.Text)b=Vai(Text2.Text)c=Vai(Text3.Text)*PI/180 角度角转换为弧度角area=a*b*Sin(c)/2Text4 =CStr(Format(area,0.00)使纯小数能出现整数位的0End SubPrivate SubCommand2_Click()Textl.Text=Text2.Text=Text3.Text=End Sub-一 区 庖惠)Private Sub
15、Command3_Click()EndEnd Sub计算 清除 退出第五章1.Option ExplicitPrivate SubCommand l_Click()D im a As Integer,bAs Integera=1:b=0D o While a=20 Then Exit For 跳出循环前执行不到这一句Next iPrint i,pEnd SubPrivate Sub Command4 _Click()D im p As Integer,i As Integer,n As Integerp=2:n=20For i=1 To n Step p 计数循环的初值、终值和步长都不会变P=
16、P+2n =n -3i=i+1If p =1 0 T hen Exit Fo rNext iPr in t i,p,nEn d S u b2.*Forl 匚 叵区清除73423558146851185545353154781589333*2147185881426887169826649:35个统计个数1862956621个为186713269334数966109681285:个A7933(14291&1为妹3743529161986636123436816398119539448546据701数于6287M637037748092温疆8794947321于小的5478944375等4070生
17、成100个随机数173114157184111936146191160156舞灯数数Op tio n Exp licitDim n l As In teger,n 2 As In teger,n 3 As In tegerPr ivate S u b Co mman dl_Click()Dim i As In teger,j As In teger,k As In tegerFo r i=1 T o 1 0Fo r j=1 T o 1 0k=In t(Rn d*90 +1 0)Pr in t k;If k=4 0 T henn l=n l+1Elself k=70 T henn 2 =n 2
18、+1Elsen 3 =n 3 +1En d IfNext jPr in tNext iEn d S u bPr ivate S u b Co mman d2 _Click()Pr in t 小于等于4 0的数据个数为:&n l&个 Pr in t”大 于4 0小于等于7 0的数据个数为:&n 2&个 Pr in t 大于70的数据个数为:&n 3&个 En d S u bPr ivate S u b Co mman d3 _Click()CisEn d S u bOp tio n Exp licitPr ivate S u b Co mman d1 _C1 ick()Dim x As In t
19、eger,y As In tegerx=T extl.T extIf x=0 T heny=2 -xElself x=2 T heny=x+2Elself x=5 T heny=x-2Elsey=2 5 -xEn d IfT ext2.T ext=yEn d S u bPr ivate S u b Co mman d2 _Click()T extl.T ext=T ext2 =En d S u b4.Op tio n Exp licitPr ivate S u b Co mman dl_Click()Dim i As In teger,j As In teger,k As In tegerFo
20、 r i=1 T o 2Fo r j=1 T o 1 0k=In t(Rn d*90 0 +1 0 0)Pictu r el.Pr in t k;If k Mo d 200 T henListl.Additem kElseList2.Additem kEn d IfNext jPictu r el.Pr in tNext iEn d S u b5.Op tio n Exp licitPr ivate S u b Co mman d1 _C1 ick()Dim m As In teger,n As In teger,r As In tegerm=V ai(T extl.T ext)nV ai(T
21、 ext2.T ext)Dor =m Mo d nIf r 0 T henm=nn =rElseExit DoEn d IfLo o pT ext3.T extV ai(T ext2.T ext)/nEn d S u bV ai(T extl.T ext)*6.Op tio n Exp licitDim r l As In teger,r 2 As S in gle r 2 可能是个很大的数,最好定义成单精度型Pr ivate S u b Co n mian dl_Click()Dim i As In teger,k As In tegerr l=0:r 2 =1 r 2 一定要初始化为1,否
22、则积为 0Fo r i=1 T o 1 0k=In p u tBo x(请输入第&i&个数)Pictu r el.Pr in t k;r l=r l+kr 2 =r 2 *kNext iEn d S u bPr ivate S u b Co n iman d2 _Click()T extl=r lEn d S u bPr ivate S u b Co mman d3 _Click()T ext2 =r 2En d S u b7.iOp tio n Exp licitPr ivate S u b Co mman d1 _C1 ick()Dim s As S tr in g,si As S tr
23、in g,s2 As S tr in g,As In tegersi=T extl.T extFo r i=1 T o Len(sl)s=Mid(sl,i,1)If s=0 An d s 仁“9 T hens2En d IfNext iT ext2.T extEn d S u b=s2=s28.Op tio n Exp licitPr ivate S u bCo mman dl_Click()T extl=”T ext2 =En d S u b&sPr ivate S u b Co mman d2 _Click()Dim n As In teger,r As S tr in g,s As S
24、tr in gn =V ai(T extl.T ext)Dor =n Mo d 2s=r&sn =n 2Lo o p U n til n =0 当商为0时则跳出循环T ext2.T ext=sEn d S u bOp tio n Exp licitPr ivate S u b Co mman d1 _Click()Dim a As Lo n g,b As Lo n g,c As Lo n gFo r a1 T o 1 0 0Fo r b=1 T o 1 0 0Fo r c=1 T o 1 0 0I f a*a+b*b=c*c T henListl.Additem a&b&cEn d IfNex
25、t cNext bNext aEn d S u b1 0.Op tio n Exp licitPr ivate S u b Co mman dl_Click()Dim i As In teger,r l As In teger,r 2 AsIn teger,r 3 As In tegerFo r i=1 0 0 T o 999r l=i 1 0 0r 2 =(i 1 0)Mo d 1 0 或者 r 2 =(i mo d1 0 0)1 0r 3 =(i Mo d 1 0 0)Mo d 1 0If r l r 2 An d r 2 0 Thena=cElseb=cEnd Ifc=(a+b)/2Lo
26、op Until Abs(b-c)2 0 T hen p =p -2 0n =n +a(p)Next jIf n max T henmax=nw=iEn d IfNext iT ext2 =maxPictu r el.Pr in t w&一&w+4En d S u bPr ivate S u b Co mman d3 _Click()T extl=En d S u bPr ivate S u b Co mman d4 _Click()En dEn d S u b6 5Dim a(5,5)As In tegerPr ivate S u b Co mman dl_Click()Fo r i=1 T
27、 o 4Fo r j=1 T o 5a(i,j)=In t(9*Rn d)+1Pictu r el.Pr in t a(i,j);Next jPictu r el.Pr in tNext iEn d S u bPr ivate S u b Co mman d2 _Click()Fo r j=1 T o 5s=0Fo r i=1 T o 4s=s+a(i,j)Next iT extl=T extl&S tr(s)Next jEn d S u bPr ivate S u b Co mman d3 _Click()Fo r i=1 T o 4s=0Fo r j=1 T o 5s=s+a(i,j)Ne
28、xt jT ext2 =T ext2&S tr(s)&Chr(1 3)&Chr(lO)Next iEn d S u bPr ivate S u b Co mman d4 _Click()T extl_,”T ext2 =Pictu r el.CisEn d S u bPr ivate S u b Co mman d5 _C1 ick()En dEn d S u b6-6Op tio n Exp licitPr ivate S u b Co mman d1 _Click()Dim a(5,5),i As In teger,j AsDim n As In teger,m As In teger,R
29、an do mizeFo r i=1 T o 5Fo r j=1 T o 5 -1a(i,j)=I n t(4 0 *Rn d)Next jNext iFo r i=1 T o 5Fo r j=5 T o 6-i S tep -1a(i,j)=In t(4 0 *Rn d)Next jNext iFo r i=1 T o 5Fo r j=1 T o 5In tegert As In teger*2+1 0*2+1 1T extl=T extl&S tr(a(i,j)Next jT extl=T extl&vbCr LfNext iEn d S u b6-7 同 6 46-8Dim a(5,5)
30、As In tegerPr ivate S u b Co mman dl_Click()Ran do mizeFo r i=1 T o 5Fo r j=1 T o 5a(i,j)=In t(1 0 0 *Rn d)+1Pictu r el.Pr in t Right(&a(i,j),4);Next jPictu r el.Pr in tNext iEn d S u bPr ivate S u b Co mman d2 _Click()Fo r i=1 T o 5Fo r j=1 T o 5s=s+a(i,j)Next jNext iT extl=S tr(s)En d S u bPr ivat
31、e S u b Co n iman d3 ClickOFo r i=1 T o 5Fo r j=1 T o 5I f i=10rj=10ri=50rj=5 T hens=s+a(i,j)En d IfNext jNext iT ext2 =S tr(s)En d S u bPr ivate S u b Co mman d4 _Click()Fo r i=1 T o 5Fo r j=1 T o 5I f i=j 0rj=6-i T hens=s+a(i,j)En d IfNext jNext iT ext3 =S tr(s)En d S u b6-9Op tio n Exp licitPr iv
32、ate S u b Co mman dl_Click()Dim a()As In teger,i As In teger,j AsIn tegerDim max As In teger,k As In teger,f AsBo o leanDim n As In teger,m As In teger,t As In tegern =In p u tBo x(输入矩阵的行数:”)m=In p u tBo x(输入矩阵的列数:”)ReDim a(n,m)Ran do mizeFo r i=1 T o nFo r j=1 T o ma(i,j)=In t(90 *Rn d)+1 0T extl=T
33、 extl&S tr(a(i,j)Next jT extl=T extl&vbCr LfNext iFo r i=1 T o nmax=0Fo r j=1 T o mIf a(i,j)max T henmax=a(i,j)t=jEn d IfNext jFo r k=1 T o nIf a(k,t)n T henPictu r el.Pr in t 鞍 点:“;a(i,t);第”;i;”行;t;列 f=T r u eEn d IfNext iIf f=False T hen Pictu r el.Pr in t”没有鞍点”En d S u bPr ivate S u b Co mman d2
34、_Click()T extl=Pictu r el.CisEn d S u bPr ivate S u b Co mman d3 _Click()En dEn d S u b6-1 0Op tio n Exp licitPr ivate S u b Fo r m_Click()Dim a()As In teger,n As In tegerDim i As In teger,j As In tegern =In p u tBo x(层数”)ReDim a(n,n)Fo r i=1 T o nPr in t T ab(2 0 -2 *i);Fo r j=1 T o iIf i=1 Or i=j
35、T hena(i,j)=1Elsea(i,j)=a(i-1,j-1)+a(i-1,j)En d IfPr in t Left(a(i,j)&,4);Next jPr in tNext iEn d S u b6-1 1数组行交换6-1128 70 33 12 8224 26 33 33 5726 34 54 34 7838 34 55 71 92运行28 70 33 12 8238 34 55 71 9226 34 54 34 7824 26 33 33 57max彳 J 和,2 90 min 行 和:1 73max彳 亍,4 min f:2 交换这两行Op tio n Exp licitPr
36、ivate S u b Co n iman dl_Click()Dim a(4,5),i As In teger,j As In tegerDim b(4)As In teger,max As In teger,min AsIn tegerDim n As In teger,m As In teger,t As In tegerRan do mizemax=0:min =3 2 767Fo r i=1 T o 4Fo r j=1 T o 5a(i,j)=In t(90 *Rn d)+1 0T extl=T extl&S tr(a(i,j)b(i)=b(i)+a(i,j)Next jT extl
37、=T extl&vbCr LfIf max b(i)T henmin =b(i):n =iEn d IfNext iLabel 1.Cap tio n =max 行和:&max&min行 和:&min&vbCr Lf&max 行:&m&min 行:&n&交换这两行Fo r j=1 T o 5t=a(m,j)a(m,j)=a(n,j)a(n,j)=tNext jFo r i=1 T o 4For j=1 To 5Text2=Text2&Str(a(i,j)Next jText2=Text2&vbCrLfNext iEnd Sub6-12Option ExplicitPrivate Sub Com
38、mandl_Click()D im a(),i As Integer,j As IntegerD im b(4)As Integer,max As Integer,min AsIntegerD im n As Integer,m As Integer,t As IntegerRandomizen=InputB ox(矩阵阶数 n:)ReD im a(n,n)For i=1 To nFor j=1 To na(i,j)=Int(90*Rnd)+10Textl=Textl&Str(a(i,j)Next jTextl=Textl&vbCrLfNext iFor i=1 To nFor j=1 To
39、nText2=Text2&Str(a(j,i)Next jText2=Text2&vbCrLfNext iEnd SubPr ivate S u b Co mman d2 _Click()T extl=T ext2 =”En d S u bPr ivate S u b Co mman d3 _Click()En dEn d S u b6-1 3Op tio n Exp licitOp tio n Base 1Pr ivate S u b Co mman dl_Click()Dim a(3,3)As In teger,i As In teger,j AsIn tegerDim max As Lo
40、 n g,k As Lo n g,f As In tegerDim n As In teger,m As In tegerRan do mizeFo r i=1 T o 3Fo r j=1 T o 3a(i,j)=In t(90 *Rn d)+1 0T extl=T extl&S tr(a(i,j)Next jT extl=T extl&vbCr LfNext iFo r i=1 T o 3 主对角线方向m=ik=Fo r j=1 T o 3k=k*a(m,j)m=m+1If m 3 T hen m=1Next jIf k max T henmax=kn =if=1En d IfNext iF
41、o r i=1 T o 3 辅对角线方向m=ik=1Fo r j=1 T o 3k=k*a(j,m)m=m-1If m max T henmax=kn =if=2En d IfNext iPictu r el.Pr in t”最大组元素:”If f=1 T henFo r i=1 T o 2Pictu r el.Pr in t a(;n;i;a(n,i);”n =n +1If n 3 T hen n =1Next iPictu r el.Pr in t a(;n;i;a(n,i)Elself f=2 T henFo r i=1 T o 2Pictu r el.Pr in t a(;i;n;a(
42、i,n);n =n -1If n 9k=k+1If i+1 3 An d j+1 =3 T heni=1:j=j+1Elself i+1 3 T heni=i+1:j=1Elself i+1 3 And j+1 3 Theni=i-1Elself i+1=3 And j+1=3 And a(i+1,j+1)0 Theni=i-1Elsei=i+1:j=j+1End Ifa(i,j)=kLoopFor i=1 To 3For j=1 To 3Picturel.Print a(i,j);Next jPicturel.PrintNext iEnd SubPrivate Sub Command2_Cl
43、ick()D im a()As Integer,i As Integer,j AsIntegerD im k As IntegerD im n As Integern=InputB ox(幻方阶数:”)ReD im a(n,n)i=n:j=(n+1)/2:a(i,j)=1:k=1D o Until k n*nk=k+1If i+1 n And j+1=n Theni=1:j=j+1Elself i+1 n Theni=i+1:j=1Elself i+1 n And j+1 n Theni=i-1Elself i+1=n And j+1=n And a(i+1,j+1)0 Theni=i-1El
44、sei=i+l:j=j+1En d Ifa(i,j)=kLo o pFo r i=1 T o nFo r j=1 T o nPictu r el.Pr in t Right(z,&a(i,j),4);Next jPictu r el.Pr in tNext iEn d S u b6-1 5蒿副对角相加6-15 国 回 区I2528973656629588997886158828525695695268)=)=3214出退Op tio n Exp licitOp tio n Base 1Pr ivate S u b Co mman dl_Click()Dim a()As In teger,i A
45、s In teger,j AsIn tegerDim max As Lo n g,k As Lo n g,f As In tegerDim n As In teger,m As In tegerRan do mizef=In p u tBo x(输入方阵阶数:”)ReDim a(f,f)Fo r i=1 T o fFo r j=1 T o fa(i,j)=In t(90 *Rn d)+1 0T extl=T extl&S tr(a(i,j)Next jT extl=T extl&vbCr LfNext iFo r i=1 T o f 副对角线方向m=ik=0Fo r j=1 T o fk=k+
46、a(j,m)m=m-1If m max T henmax=kn =iEn d IfNext iPictu r el.Pr in t max:maxFo r i=1 T o fPictu r el.Pr in t a(;i;n;a(i,n)n =n -1If n =n T henaa(n)=an =n +1En d Ifa=In t(1 0 0 *Rn d()*1)Lo o p While n Max ThenMax=smaxi=iEnd IfNext iPrint Str(a(maxi)&+&Str(a(maxi+1)&+&Str(a(maxi+2)&+&Str(a(maxi+3)&Str(M
47、ax)End Sub10.Private Sub Command1_Click()D im a(5,5)As IntegerRandomizeFor i=1 To 5For j=1 To 5a(i,j)=Int(100*Rnd)Print a(i,j);Next jPrintNext iCall fmax(a)End SubPrivate Sub fmax(a()As Integer)Max=a(l,1)maxi=1maxj=1Fo r i=1 T o 5Fo r j=1 T o 5If a(i,j)Max T henMax=a(i,j)maxi=imaxj=jEn d IfNext jNex
48、t iPr in t”最大元素为:a(“+S tr (maxi)+S tr (maxj)+)=+CS tr (Max)En d S u b1 1 .Pr ivate S u b Co mman dl_Click()Dim i As In tegerFo r i=1 T o 6T extl=T extl&S tr(fab(i)Next iEn d S u bPr ivate Fu n ctio n fab(n As In teger)As Lo n gIf n =1 Or n =2 T henfab=1Elsefab=fab(n -1)+fab(n -2)En d IfEn d Fu n cti
49、o n1 2 .Pr ivate S u b Co mman d1 _C1 ick()Dim i As In tegera=In p u tBo x(请输入一个大于2的偶数:)n=V ai (a)I f n=4 T h e nPr i nt 4=2+2”E x i t S u bE nd I fF o r i =3 T o n-1 S t e p 2I f p r i m e(i)And p r i m e(n-i)T h e nPr i nt S t r(n)+=+S t r (i)+”+S t r(n-i)E x i t S u bE nd I fNe x t iPr i nt 歌德巴赫猜
50、想不对!E nd S u bPr i v at e F u nct i o n p r i m e(B y V ai n As I nt e g e r)As B o o l e anF o r i =2 T o n-1I f n Mo d i =0 T h e np r i m e =F al s eE x i t F u nct i o nE nd I fNe x t ip r i m e =T r u eE nd F u nct i o n13.Pr i v at e S u b C o m m and 1_C 1i ck()D i m i As I nt e g e rF o r i