首页 VB试题库答案

VB试题库答案

举报
开通vip

VB试题库答案Visual Basic 练习题库参考答案 一、选择题 1.B 2.B 3.C 4.B 5.A 6.D 7.A 8.B 9.B 10.A 11.D 12.B 13.D 14.C 15.D 16.C 17.C 18.B 19.B 20.D 21.C 22.B 23.A 24.B 25.B 26.C 27.B 28.B 29.C 30.B 31.B 32.B 33.B 34.A 35.C 36.A 37.B 38.A 39.D 40.A 41.A 42.B 43.D 44.C 45.A 46.C 47.A 48.A 4...

VB试题库答案
Visual Basic 练习题 用券下载整式乘法计算练习题幼小衔接专项练习题下载拼音练习题下载凑十法练习题下载幼升小练习题下载免费 库参考答案 一、选择题 1.B 2.B 3.C 4.B 5.A 6.D 7.A 8.B 9.B 10.A 11.D 12.B 13.D 14.C 15.D 16.C 17.C 18.B 19.B 20.D 21.C 22.B 23.A 24.B 25.B 26.C 27.B 28.B 29.C 30.B 31.B 32.B 33.B 34.A 35.C 36.A 37.B 38.A 39.D 40.A 41.A 42.B 43.D 44.C 45.A 46.C 47.A 48.A 49.C 50.D 51.D 52.A 53.B 54.A 55.D 56.C 57.B 58.C 59.D 60.C 61.B 62.A 63.A 64.D 65.D 66.C 67.B 68.D 69.C 70.B 71.D 72.A 73.B 74.B 75.B 76.B 77.C 78.C 79.D 80.A 81.D 82.B 83.D 84.A 85.C 86.C 87.B 88.A 89.B 90.B 91.B 92.D 93.A 94.B 95.A 96.C 97.D 98.C 99.B 100.B 101.B 102.B 103.D 104.A 105.C 106.C 107.D 108.C 109.B 110.B 111.D 112.B 113.A 114.C 115.A 116.B 117.C 118.D 119.D 120.A 121.A 122.A 123.A 124.A 125.C 126.D 127.B 128.B 129.C 130.D 131.A 132.A 133.D 134.A 135.C 136.D 137.C 138.C 139.C 140.B 141.B 142.D 143.B 144.C 145.D 146.B 147.B 148.C 149.B 150.C 151.B 152.D 153.C 154.B 155.D 156.D 157.D 158.B 159.C 160.A 161.B 162.B 163.A 164.B 165.D 166.D 167.C 168.C 169.A 170.A 171.D 172.B 173.C 174.D 175.C 176.A 177.C 178.D 179.D 180.A 181.A 182.A 183.C 184.B 185.B 186.D 187.A 188.C 189.A 190.A 191.A 192.C 193.D 194.B 195.C 196.A 197.D 198.C 199.A 200.A 201.B 202.D 203.B 204.C 205.D 206.C 207.A 208.A 209.D 210.A 211.B 212.B 213.C 214.D 215.A 216.A 217.C 218.C 219.C 220.C 221.A 222.A 223.D 224.D 225.B 226.B 227.B 228.A 229.A 230.A 231.C 232.B 233.B 234.B 235.C 236.D 237.C 238.A 239.B 240.D 241.D 242.B 243.A 244.B 245.C 246.A 247.D 248.C 249.C 250.D 251.D 252.B 253.A 254.D 255.B 256.D 257.C 258.C 259.D 260.D 261.C 262.A 263.D 264.C 265.A 266.A 267.D 268.A 269.C 270.B 271.B 272.A 273.D 274.C 275.D 276.C 277.A 278.C 279.B 280.A 二、填空题 (1) "请输入半径" (2) "输入对话框" (3) 10 (4) 11 (5) -20 (6) 4 8 (7) 12 86 (8) 4 (9) 5 (10) 6 (11) 3 5 (12) 8 16 (13) Len(text1.text) (14) W>="A" And W<="Z" Or W>="a" And W<="z" (15) " " (16) js=js + 1 (17) flg = false (18) ReDim Preserve Data(Idx) (19) Ub = Ubound(arry) (20) Exit Sub (21) Sum (22) Slen = Len(Char) (23) j = j * 10或j = 10 ^ i (24) S (25) F = True (26) 验证口令 (27) 请输入口令 (28) * (29) 3 (30) -18 (31) 6 27 (32) -2 99 (33) 1 (34) 5 (35) 9 (36) 31 (37) 63 (38) val(txtinput.text) (39) Prime(i) (40) Exit For或Exit Function (41) i>Sqr(n) (42) Len(s) (43) Mid(s,i,1) (44) Else或 "A" To "F" (45) k=k+p*Asc1 (46) Convert =k (47) EeFF (48) InputBox(msg, msgtitle) (49) i - 1 (50) a(j) > a(j+1) (51) this is a book (52) This Is A Book (53) 6.5 (54) 4 9 13 (55) 19.5 (56) 18 (57) 30 (58) 1 2 (59) 3 4 (60) 4 3 (61) 1 3 5 7 9 (62) 4 (63) 2 (64) x mod 2=0 (65) n1=n1+1 (66) sum=0 (67) k mod n=0 (68) ReDim Preserve A(j) (69) Int(Sqr(sum))^2 (70) a=10 b=15 (71) x=25 y=25 (72) a=10 b=15 (73) 这是第1次调用 s=25 (74) 这是第2次调用 s=50 (75) 这是第3次调用 s=75 (76) Sum=14 (77) Sum=10 (78) C:\Microsoft (79) VB6.exe (80) 1 3 2 (81) 1 12 2 (82) CBA (83) ABC (84) 2 (85) 3 (86) 5 (87) k=x mod 10 (88) I = I + 1 (89) ByVal n As Integer (90) n=n\10 (91) f=false (92) Sqr(p)或p-1或p/2 (93) prime=True (94) Int(Rnd*20)+10 (95) call ste(a) (96) a(i)=a(I+1) (97) a(10)=k或a(i)=k (98) True (99) i = i + 1 (100) x = x + 1 (101) 1 2 3 (102) 4 5 (103) 7 (104) C (105) CW (106) 8 (107) 4 14 80 (108) 22 10 80 (109) 12 (110) 3 (111) 3 (112) Gcd(27, 12)=3 (113) Int(90*Rnd) + 10 (114) Max = D(i) (115) D(i) < Min 或 Min > D(i) (116) Text1. Text (117) Mid(s, n+1, Len(s)-n) (118) a(i) = s (119) p & Mid(s, I, 1) (120) CStr(i) (121) i (122) ReDim (123) Int(Rnd*90)+10 (124) m (125) n (126) 12345 (127) AFT (128) AatF (129) 5 (130) 45 (131) 54 (132) 13 (133) 15 (134) 17 (135) 0 1 2 3 4 (136) 4 5 6 7 8 (137) 8 (138) VLAUSI (139) VILAUS (140) VISUAL (141) true (142) p=p+1 (143) x=x+1 (144) I mod j=0 (145) s=i (146) ByVal m As Integer,ByVal n As Integer (147) gcd=gcd(m,n) (148) gcd(n,p)=1 (149) 31 (150) 63 (151) Picture1.Picture=LoadPicture("C:\Pic\Fishing.bmp") (152) VISUAL (153) 2005.10.11 (154) 27 3 (155) 18 0 (156) Lcm=27 (157) 3 (158) 7 (159) 23 (160) 10 4 6 (161) 56 28 28 (162) K=66 (163) 4 5 6 (164) 3 6 9 (165) 2 5 8 (166) 1 4 7 (167) "S(" & CStr(x) & "," & CStr(n) & ")=" (168) Dim i as Integer, p As Single (169) p=p*i/(2*i)或p=p/2 (170) mid(st,I,1) (171) Asc(s)-Asc("A")+1或Asc(s)-64 (172) Ubound(k)或10 (173) i=d To c+1 (174) c=c+1 (175) k(i-1)>k(i) (176) BCDEAF (177) BDECAF (178) BDECAF (179) 10 6 (180) 5 16 (181) 10 6 (182) 4 (183) 2 13 (184) 16 6 10 (185) 68 26 42 (186) 68 (187) 19 (188) 15 (189) 14 (190) n1= i \ 100 (191) n = n + 1 (192) q = s mod 10 (193) Lcase(Text1.Text) (194) n=Asc(s)-Asc(“a”)+1 (195) decode=decode & Mid(r2,n,1) (196) decode=decode & Mid(r1,27,1) (197) Flag=False (198) Flag (199) k/n>1/4 And k/n<1/3 (200) k mod i=0 (201) 12 (202) 60 (203) 3 (204) 9.6 (205) L S P (206) H X F (207) B G J (208) 3 2 (209) 6 5 (210) 9 8 (211) 3 (212) x = 4 (213) 26 (214) 15 15 (215) while abs(t)>eps (26) (-1) ^ n (217) t * x ^ 2 / n (218) int(sqr(k))=sqr(k) (219) k=k+1 (220) ReDim m(n2,n2) (221) m(i, j)=” “ (222) Fz= 1E - 8 (244) 1 / fac(k) (245) Int(90*Rnd)+10 (246) k=1 (247) Instr (248) Exit Function (249) Exit Function (250) Rec(n,m,k+1) (251) 9000 * Rnd + 1000 (252) Str(x) (253) Mid(s, 3, 1) + Mid(s, 2, 1) + Left(s, 1) (254) z=66 (255) 21 38 54 (256) 1 to 9 (257) n+1 (258) b, a (259) -i (260) +i (261) 2 3 (262) 1 to 7 step 2 (263) fact*Y (264) 死循环 (265) ctrl+break (266) 72 (267) 12 (268) 8 (269) fanma (270) I=1 (271) n=n+4-26 (272) fact = fact * k (273) temp = 1 / fact(n) (274) Call compare(data, temp, flag) (275) UBound(arry) (276) 2 (277) chr(n) (278) 4 13 (279) 6 31 (280) 8 (281) 5*x+3*y+z/3=100 (282) 1 4 9 16 25 36 (283) 7 (284) 2次 (285) 8 13 (286) -p * x (287) Abs(item) >= eps (288) fx(x, result) (289) True (290) I = I + 1 (291) x = x + 1 (292) x/2或Sqr(x) (293) False (294) True (295) Fun1(x) (296) 23 (297) 47 (298) k mod 10或Right(CStr(k), 1) (299) Len(st) (300) print “*”; (301) 9 (302) 5 (303) 36 (304) 18 (305) a(I, j)=1 (306) Print (307) int(Rnd * 900 + 100)或100+Int(900*Rnd) (308) n1 = n1 + 1 (309) m=20 n=10 (310) X=10 Y=15 (311) m=20 n=10 (312) X=20 Y=10 (313) num > 1 (314) num \ 10 (315) s (316) n=1 (317) m * n * x / x ^ n (318) Picture1.Print (319) a(1, 1) (320) a(i, j) (321) s=25 (322) s=50 (323) s=75 (324) I=Fun1(i) (325) Fun1=Fun1+j (326) 窗体或控件 (327) 控件或窗体 (328) Select Case x (329) Case Else或Case Is > 100 (330) 198 (331) 2 (332) 2 (333) 6.5 (334) 4 9 13 (335) 19.5 (336) this is a book. (337) This Is A Book. (338) Mid(source, 1, 1) <> "1" (339) 2 (340) Mid(source, i, 1) = "1" (341) flag=1 (342) I mod 13=1 And I mod 23=2 And I mod 33=3 (343) Until flag=0或While flag=1 (344) fact = fact * k (345) temp = 1 / fact(n) (346) j = j + 1 (347) Call Insert(a) (348) a() As Integer (349) a(J) = a(J – 1) (350) Getp = Getp + 1 (351) m Mod 10 (352) 2^n (353) fact=1 (354)abs(x1-x2)>=1e-6或 abs(x1-x2)>=0.000001 (355) sum = 0 (356) k mod n=0 (357) ReDim Preserve a(j) (358) Sqr(sum)= Fix(Sqr(sum)) (359) 98 (360) Comp(Sum, Flg) (361) Str(n) (362) J*10 (363) False (364) Exit Sub (365) Val(Text1.Text) (366) Str(num)或num (367) P=P-2 (368) X & Str(P) (369) Command1 (370) Command2 (371) fact(i) (372) 5 (373) 9 (374) i Mod k =0 (375) Exit For (376) 2 4 6 (377) Chr(n) (378) T = t + k (379) 7 (380) 1 (381) (N mod 10)*10+N\10 (382) Int(100 + Rnd * 900) (383) s1 = s1 + 1 (384) Dim n As Integer, term As Single, t As Single (385) term = term + t (386) t = 2 To 4 (387) p + t (388) k = k + 1 (389) 23 47 (390) 47 (391)1 4 9 16 25 (392) 3 (393) 7 (394) 2 (395) i Mod 3=0 (396) d = d + 1 (397) str(d) (398) 1 To 9 (399) n = a * 100 + b * 10 + c (400)next b (401) 7 (402) dir1.path = drive1.drive (403) 1 to m (404) mid(b, j, 1) (405) abs(x-x1)<=1e-6 (406) x^3-2*x^2+7*x+4 (407) Int(Rnd*90)+10 (408) x mod 2=0 (409) n1=n1+1 (410) t Mod 2 (411) Len(b) (412) 1000 (413) n=k (414) n =n \ k (415) k = k + 1 (416) Form1.hide (417) show (418) 32 (419) val(txtInput) (420) prime(I) (421) Exit Function (422) sum = sum + i (423) sum = sum-max-min (424) sum=1 (425) sum>n (426) c<50 and c=int(c) (427) fact*y (428) Len(s) (429) mid(s, i, 1) (430) List1.AddItem k (431) x*fact(x-1) (432) prime(x) (433) false (434) 1 to 9 (435) I +1 to 10 (436) > (437) n=9 (438) n=3 (439) 6 (440) k (441) a(k, j) (442) 6 (443) 4 (444) a(1, 1) (445) MaxA(j+1) (461) 11是素数 (462) 12不是素数 (463) x Mod i = 0 (464) 6 (465) 9 (466) m=Len(s) (467) m=m-1 (468) Text2.Text="是回文" (469) i=1 (470) n=n+4-26 (471) i=i+1 (472) 0 (473) y = y / x(i) (474) 1 To i (475) sqr(Sum)=Int(Sqr(Sum)) And Sqr(c)=Int(Sqr(c)) (476) 6 4 (477) 3 21 (478) 32 (479) 1 2 3 (480) 6 (481) 1 (482) 等/级/考/试/ (483) i+1 (484) A(i)0或Num (494) Num\10 (495) S (496) fac = 1 (497) Abs(x) >= 1E - 8 (498) x = 1 / fac(k) (499) 4*fun1(n) (500) (-1)^(i-1)/(2*i-1) (501) 21 (502) 13 21 (503) 15 16 (504) 265 (505) abdb (506) 3 182 (507) 11 7 (508) n\3 (509) 11 (510) 5 (511) Int(90*Rnd+10) (512) 10-i (513) A(J) > A(J + 1) (514) 15 30 (515) 15 15 (516) 6 (517) 13 (518) (519) Sub=11 21 44 (520) Main=11 17 41 (521) M = num (522) num = num \ 10 (523) ByVal n As Integer (524) k = n Mod 2 (525) Right(S, 4) (526) 200 (527) 10 (528) 0 :1 (529) 2 :3 (530) 4 :1 (531) 11 (532) 61 (533) 136 (534) 01 05 02 (535) 08 (536) 03 (537) 4 (538) 8 (539) 16 (540) Until Len(CStr(A(I, J))) = 2 (541) L = 6 - J (542) R = 6 - I (543) Chr(65 + I) (544) Loc(12) < LOF(12) (545) Get #12, , S (546) Rc_NO = Rc_NO + 1 (547) n = n + 1 (548) st = "" (549) n + Val(Mid(S, j, 1)) * 2 ^ (8 - j) (550) n = 0 三、改错题(12分) 1.Option Explicit Private Sub Form_Click() Dim A() As Single, I As Integer Dim Y As Single I=1 Do ReDim A(I) ‘ReDim Preserve A(I) A(I)=1/Fib(I) If A(I)<=e-4 Then Exit Do ‘1e-4 Y=Y+A(I) I= I + 1 Loop Print "Y="; Y End Sub Private Function Fib(I As Integer) As Integer If I = 1 then Fib = 1 ElseIf I=2 Then Fib=2 Else Fib(I)=Fib(I-1)+Fib(I-2) ‘Fib=Fib(I-1)+Fib(I-2) End if End Function 2.Option Explicit Private Sub Form_Click() Dim Fac() As Integer, N(3)As Integer Dim I As Integer, J As Integer N(1)=48:N(2)=308:N(3)=1155 For I=1 To 3 Call Factor(Fac, N(I)) Print N(I);"的质因子是:"; For J=l To UBound(Fac) Print Fac(J); Next J Print ReDim Fac(1) Next I End Sub Private Sub Factor(F()As Integer, ByVal N()As Integer) ‘Byval N As Integer Dim I As Integer, J As Integer, Idx As Integer Dim K As Integer K=2 Do Until N=1 If N Mod K=0 Then Idx=Idx +1 ReDim F(Idx) ‘Preserve F(Idx) F(Idx)=K N=N/K Else n=n+l ‘k=k+1 End If Loop End Sub 3.Option Explicit Option Base 1 Private Sub getn(s As String, ByVal d() As Integer) ‘d() as Integer Dim k As Integer, st As String, n As Integer, f As Boolean k = 1: n =1 Do Until n > Len(s) If Mid(s, n, 1) >= "0" And Mid(s, n, 1) <= "9" Then st = st & Mid(s, n, 1) f = True ElseIf f Then f = False ReDim Preserve d(k) d(k) = Val(st) st = " " k = k +1 End If n = n + 1 Loop End Sub Private Sub Form_Click() Dim P As String, num() As Integer, i As Integer Dim s As Integer, av As Integer ‘av as single P = "ags43dhbc765shdk8djfk65bdgth23end'' Call getn(s, num) ‘getn(P, num) For i = 1 To UBound(num) s = s + num(i) Print num(i) Next i Print av = s / UBound(num) Print "s="; s, "av="; av End Sub 4.Option Explicit Private Sub ars(k As Long, num()As Integer) ‘ByVal kAs Long Dim i As Integer For i=1 To Len(CStr(k)) Num(i)=k Mod 10 k=k \ 10 Next i End Sub Private Sub Form_Click() Dim n As Integer, i As Long, num( ) As Integer Dim cb As Integer, ct As Long, J As Integer, s As Long n=InputBox("要查找的Armstrong数的位数:", , 2) cb=Val(Left("100000", n)) ct=Val(Left("999999",n)) ReDim num(n) For i=cb To ct Call ars(n, num) ‘改为call ars(I, num) For J=l To UBound(num) S=0 ‘位置错 S=S + num(j)^n Next j If s=i Then Print I; "是一个Armstrong数! " Next i End Sub 5.Option Explicit Option Base 1   Private Sub Command1_Click() Dim i As Integer, A(10) As Integer, Sum As Integer For I=1 To 10 A(i)=val(InputBox("请输入数据")) Next I For I=1 To 10 If Prime(A()) Then ‘Prime(A(i)) Print A(i); Sum = Sum + A(i) End If Next I Print "最后结果="; Sum End Sub Private Function Prime(d As Integer) As Integer Dim i As Integer Prime=0 ‘Prime=1 For I=2 To Sqr(d) If d Mod I=0 then Prime=1 ‘Prime=0 Next i End Function 6. Option Explicit Private Function pt(x As Single, n As Integer) As Double Dim p As Integer, i As Integer ‘改为Single p = 1 For i = 1 To n p = p * i / (x + i) Next i pt = p End Function Private Sub Form_Click() Dim x As Single, k As Integer Dim a As Double, s As Double Do x = InputBox("输入一个大于1的数:", , 1) If x <= 1 Then MsgBox "数据错误,重输!", vbOKOnly Loop Until x < 1 ‘改为x>1 k = 1 Do a = pt(x) ‘改为pt(x,k) s = s + a If a <= 0.000001 Then Exit Do k = k + 1 Loop Print s End Sub 7.Option Explicit Option Base 1 Private Sub Form_Click() Dim a(10) As Integer, i As Integer Dim St As String, t As Integer, j As Integer Randomize For i = 1 To 10 a(i) = Int(Rnd * 100) + 900 ‘改为Int(rnd*900)+100 St = St & Str(a(i)) Next i Text1.Text = St For i = 1 To 10 If flag(a(i)) Then Text2 = Text2 & Str(a(i)) End If Next i End Sub Private Function flag(ByVal n As Integer) As String ‘改为Boolean Dim i As Integer, a(3) As Integer flag = True ‘改为False For i = 2 To Sqr(n) If n Mod i = 0 Then Exit Function Next i If i > Sqr(n) Then flag = True End If End Function 8.Option Explicit Dim a() As Integer, i As Integer Private Sub Form_Click() Dim k As Integer, t As Integer, j As Integer For i = 1 To UBound(a) Print a(i); Next i Print k = 1 For i = 2 To n ‘改为For I = 2 To UBound(a) If a(i) <= a(k) Then t = a(k) a(k) = a(i) For j = i To k + 1 Step -1 a(j + 1) = a(j) ‘改为a(j – 1) = a(j) Next j k = k + 1 ‘k=k+1与a(k)=t调换位置 a(k) = t End If Next i For i = 1 To UBound(a) Print a(i); Next i End Sub Private Sub Form_Load() Dim n As Integer, i As Integer Randomize n = InputBox("输入数据个数:", , "10") ReDim a(n) For i = 1 To n a(i) = Int(Rnd * 90) + 10 Next i End Sub 9.Option Explicit Private Sub Command1_Click() Dim i As Integer, k As Integer, st As String For i = 10 To 500 If wanshu(i) Then st = CStr(i) Text1.Text = Text1.Text & st Call test(st) Text1.Text = Text1.Text & Chr(13) & Chr(10) End If Next i End Sub Private Function wanshu(n As Integer) As Boolean Dim i As Integer, sum As Integer For i = 1 To n – 1 ‘改为For I=2 to n-1 If n Mod i = 0 Then sum = sum + i End If Next i If sum = n Then wanshu = True End Function Private Sub test(s As String) Dim i As Integer, sum As Integer Do While Len(s) > 1 sum = 0 ‘sum=0调到Do语句之前 For i = 1 To Len(s) sum = sum + Val(Mid(s, i, 1)) Next i Text1.Text = Text1.Text & "->" & Str(sum) s = Str(sum) ‘改为s = CStr(sum) Loop End Sub 10.Private Sub Form_Click() Dim i As Integer, j As Integer, t As Integer Dim a(1 To 10) As Integer Randomize Print "原始数据:" For j = 1 To 10 a(j) = Int(100*Rnd) ‘改为Int(91*Rnd+10) Print a(j); Next j Print:Print For i = 1 To 9 For J = i+1 To 10 If a(j) > a(i) Then ‘改为a(i) > a(j) t = a(i): a(j) = a(i): a(j) = t ‘改为a(i) = a(j) End If Next j Next i Print "排序结果:" For j = 1 To 10 Print a(j); Next J End Sub 11.Option Explicit Private Sub Form_Click() Dim n As Integer, k As Long Dim m As Long, f As Integer n = Val(InputBox("请输入一个大于2的整数")) m = 0 ‘改为m=1 For k = 1 To n m = m * k Next k For k = n + 1 To m - 1 f = flag(k) If f = 0 Then Exit For ‘改为f=1 Next k If f = 1 Then Print n; "与"; m; "之间的一个素数是"; k Else Print n; "与"; m; "之间没找到一个素数" End If End Sub Private Function flag(n As Long) As Integer Dim i As Integer flag = 1 For i = 2 To Sqr(n) If n Mod i <> 0 Then ‘改为n Mod I=0 flag = 0 Exit For End If Next i End Function 12.Dim a(1 To 10)As Integer Private Sub Form_Click() Dim P As String,yes As Boolean,X As Integer Dim i As Integer,j AS Integer Randomize P="" For I=1 To 10 Do X=Int(Rnd*90)+10 yes=0 For j=1 To I-1 If X-a(j) Then yes=1: Exit For ‘改为: X=a(j) Next j Loop While yes=1 a(i)=P ‘改为:a(i)=x Next i For I=1 To 10 ‘改为:For I=1 To 9 For j=i+1 To 10 If a(i)>a(j) Then T=a(i) a(i)=a(j) a(j)=t End If Next j Next i P=Str(a(1)) For i=2 To 10 P=P & "," & Str(a(i)) Next i Picture1.Print P End Sub 13.Option Explicit Option Base 1 Private Sub Command1_Click() Dim I As Integer, K As Integer, Sum As Integer For I = 2 To 2000 Sum = 0 ‘从for语句前调换到这里 Call Factor(I, Sum) If Prime(Sum) Then K = K + 1 Text1.Text = Text1.Text & Str(I) & " " If K Mod 5 = 0 Then Text1 = Text1 & vbCrLf End If Next I End Sub Private Sub Factor(N As Integer, S As Integer) Dim I As Integer, J As Integer Do While I < N I = I + 1 ‘调换位置 If N Mod I = 0 Then S = S + I End If Loop End Sub Private Function Prime(N As Integer) As Boolean Dim M As Integer For M = 2 To Sqr(N) If N Mod M = 0 Then Exit Function ‘改为Exit Function Next M Prime = True End Function 14.Option Explicit Option Base 1 Private Sub Command1_Click() Dim a(10) As Integer, i As Integer Dim st As String, t As Integer, j As Integer Randomize For i = 1 To 10 a(i) = Int(Rnd * 900) + 100 st = st & Str(a(i)) Next i Text1 = st For i = 1 To 10 If Flag(a) Then ‘改为flag(a(i)) t = a(i) For j = i - 1 To 1 Step -1 a(j - 1) = a(j) ‘改为a(j + 1) Next j a(1) = t End If Next i st = "" For i = 1 To 10 st = st & Str(a(i)) Next i Text2 = st End Sub Private Function Flag(ByVal n As Integer) As Boolean Dim i As Integer, a(3) As Integer For i = 1 To 3 a(i) = Mid(Str(n), i, 1) ‘改为mid(CStr(i), I , 1) Next i If a(1) <= a(2) And a(2) <= a(3) Then Flag = True Else Flag = False End If End Function 15.Option Explicit Private Sub Form_Click() Dim Prm()As Integer, Fm As Single, Fz As Single Dim Sum As Single, N As Integer, S As Single ReDim Prm(1) Prm(1)=2 Call Prime(Prm) Fm=1 Do N=N+1 Fm=Prm(N)*Fm S=S+N/Fm loop Until Abs(Fm)<0.0000001 ‘改为 Abs(N/Fm) Print "S="; S End Sub Private Sub Prime(P As Integer) ‘改为 P() As Integer Dim I As Integer, Idx As Integer, K As Integer Idx=1 For I=3 To 500 Step 2 For K=2 To Sqr(I) If I Mod K=0 Then Exit For Next K If K>Sqr(I) Then Idx=idx+1 ReDim P(Idx) ‘改为 ReDim Preserve P(Idx) P(Idx)=I End If Next I End Sub 16.Option Explicit Private Function fib(n As Integer)As Long If n=1 And n=2 Then ‘and 改为 or fib=1 Else fib=fib(n-1)+fib(n-2) End If End Function Private Function prime(n As Integer)As Boolean Dim k As Integer prime=False For k=2 To Sqr(n) If n Mod k<>0 Then Exit Function ‘改为n mod k=0 Next k prime=True End Function Private Sub Command1_Click() Dim temp As String, k As Integer, P As Long K=1:P=fib(k) Do Until Len(temp)>4 temp=Str(P) If Len(temp)=2 or Len(temp)=3 Then List1.Addhem P End If k=k+1 P=fib(k) Loop Temp=” “ For k=0 To List1.ListCount ‘改为List1.ListCount-1 If Not prime(List1.List(k)) Then Temp=temp & List1.List(k) & Chr(13) & Chr(10) End If Next k Text1=temp End Sub 17.Option Explicit Option Base 1 Private Sub Command1_Click() Dim I As Integer, K As Integer, Sum As Integer Sum=0 ‘将sum=0与for i=2 to 2000对调 For I=2 to 2000 Call Fctor(I, Sum) If Prime(Sum) Then K=K+1 Text1.Text=Text1.Text & str(I) & “ “ If K Mod 5=0 Then Text1=Text1 & Chr(13) & Chr(10) End If Next I End Sub Private Sub Fctor(N As Integer, S As Integer) Dim I As Integer, J As Integer Do While I
本文档为【VB试题库答案】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_718205
暂无简介~
格式:doc
大小:229KB
软件:Word
页数:36
分类:工学
上传时间:2010-10-11
浏览量:498