VB考试复习题_第1页
VB考试复习题_第2页
VB考试复习题_第3页
VB考试复习题_第4页
VB考试复习题_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、x<y<z。1、已知 x,y,z 3个变量中存放了 3 个不同得数,比较它们得大小并进行调整,使得 Private Sub Command1_Click() Dim x!, y!, z!z"x = InputBox("input x") y = InputBox("input y") z = InputBox("input z") Print Tab(8); " " "x" "y" "Print "排序前 :" x; &qu

2、ot; " y; " " z If x < y Then t = x: x = y: y = t: If x < z Then t = x: x = z: z = t: If y < z Then t = y: y = z: z = t: Print "排序后 :" "" z; " " y; " " x End Sub 2、 0到 200 被 5 或 11 整除得数得与 Private Sub Command1_Click() Dim i% For i = 0 To

3、200If i Mod 11 = 0 Or i Mod 5 = 0 Then Sum = Sum + iEnd IfNext iPrint "总与就是 " SumEnd Sub3、从键盘输入三角形得三条边 a,b,c 得值,根据其数值,判断能形。Private Sub Command1_Click()Dim a%, b%, c%a = Val(InputBox("inputa")b = Val(InputBox("inputb")c = Val(InputBox("inputc")If a + b > c A

4、nd b + c > a And a + c > b ThenMsgBox ("能构成三角形 ")ElseMsgBox ("不能构成三角形 ")End IfEnd Sub4、随机产生 10 个 30,100内得整数,求最小值及所对应得下标。 Private Sub Form_click()Dim a(1 To 10) As Integer, zb%, mina%, i%For i = 1 To 10 a(i) = Int(Rnd * 71 + 30) Print a(i);Next izb = 1mina = a(1)For i = 2 To

5、 10If mina > a(i) Then mina = a(i): zb = iNext iPrintPrint "min=" mina, " 下标 =" zbEnd Sub5、随机产生 10 个 30,100内得整数,求最大值、最小值与平均值。 Dim a(1 To 10) As Integer, amin, amax, i%, avera!Private Sub Form_Click()For i = 1 To 10a(i) = Int(Rnd * 71 + 30)Next i amin = a(1) amax = a(1) avera =

6、 a(1)For i = 2 To 10If a(i) > amax Then amax = a(i)If a(i) < amin Then amin = a(i) avera = avera + a(i)Next iFor i = 1 To 10Print a(i);Next iPrintPrint "max=" amax, "min=" amin, "avera=" avera / 10End Sub6、随机产生 10 个 30,100内得整数,求最大值及所对应得下标 Private Sub Form_Click()D

7、im a(9), max%, imax%For i = 0 To 9a(i) = Int(Rnd * 71 + 30)Print a(i);Next iPrint max = a(0) For i = 1 To 9If max < a(i) Then max = a(i): imax = iNext iPrint "max=" maxPrint "下标 =" imaxEnd Sub7、某次歌曲大奖赛,有 7 个评委。如果分别输入 7 个评委对某个参赛者得打分数,按照去 掉一个最高分与一个最低分得计算办法,求出该参赛者得平均得分。Private Su

8、b Command1_Click()Dim mark!, max!, min!, aver!, i% aver = 0For i = 1 To 7mark = InputBox("输入第” & i & ”位评委得打分”)If i = 1 Thenmax = mark: min = markElseIf mark < min Then min = markIf mark > max Then max = markEnd If aver = aver + markNext i aver = (aver - min - max) / 5Print averEnd

9、 Sub8,9、求s=a+aa+aaa+、aaaaa (n个a),其中a与n得值随机产生,a得范围就是1,9得整 数, n 得范围就是 5,10 。s。如 a=3,n=6,则 s=3+33+333+3333+33333+333333。编程确定 n 与 a得值,并计算Private Sub Form_click()Dim s!, t!, i!, a%, n%a = Int(Rnd * 9 + 1)n = Int(Rnd * 6 + 5) t = 0: s = 0Print Tab(9); "a=" a, "n=" nPrintFor i = 1 To n

10、t = t * 10 + a s = s + tPrint Tab(9); tNext iPrintPrint Tab(9); "s=" Val(s)End Sub10、产生 1100 以内得素数Private Sub Command1_Click()Dim i%, j%, tag As BooleanFor j = 1 To 100tag = TrueFor i = 2 To j - 1If j Mod i = 0 Then tag = FalseNext iIf tag Then Print j;Next jEnd Sub11、计算 100300 之间所有能被 3 与

11、7 整除得数之与。 Private Sub Command1_Click()Dim s%, i%s = 0For i = 100 To 300If i Mod 3 = 0 Or i Mod 7 = 0 ThenEnd IfNext iPrint "s=" & sEnd Sub12、输入一年份,判断她就是否为闰年,并现实就是否就是闰年得有关信息。Private Sub Command1_Click()Dim y%y = Val(Text1)If y Mod 4 = 0 And y Mod 100 <> 0 Or y Mod 400 = 0 ThenMsgB

12、ox (y & "年就是闰年 ")ElseMsgBox (y & "年就是平年 ")End IfEnd Sub13、编程求 200-400 范围内 5 得倍数或 7 得倍数之与。 (一个数如果同时就是 7 与 5 得倍数, 则只能加一次。 )Private Sub Command1_Click()Dim s1%, s2%, s3%, i%s1 = 0 s2 = 0For i = 200 To 400If i Mod 5 = 0 Or i Mod 7 = 0 Then s1 = s1 + iEnd IfNext iFor i = 200 T

13、o 400If i Mod 5 = 0 And i Mod 7 = 0 Then s2 = s2 + iEnd IfNext i s3 = s1 - s2Print s3End Sub14、利用 inputbox 函数输入两个整数,求它们得最大公约数Private Sub Command1_Click()n1 = InputBox(" 输入 n")m1 = InputBox(" 输入 m")If m1 > n1 Thenm = m1: n = n1Elsem = n1: n = m1End Ifr = m Mod nDo While r <&

14、gt; 0r = m Mod nLoopPrint "m n 得最大公约数就是: " n End Sub 15、随机产生一个三位正整数,然后逆序输出,产生得数与逆序数同时显示。例如,产生 246,输出就是 642。Private Sub Command1_Click()Text1 = Int(Rnd * 900 + 100)End SubPrivate Sub Command2_Click()Dim x%, x1%, x2%, x3%x = Val(Text1)x1 = x Mod 10 x2 = (x Mod 100) 10x3 = x 100Text2 = x1 * 1

15、00 + x2 * 10 + x3End Sub 方法二:Dim a%, m%, b%, c%, d% Private Sub Form_Click() a = Int(Rnd * 900 + 100) Print a d = (a Mod 10) * 100 b = (a Mod 100) - (a Mod 10) c = a 100Print mEnd SubABCDEFG 变16、从键盘输入任意长度得字符串,要求将字符顺序倒置,例如,将输入得“ 换成“ GFEDCBA。Private Sub Form_Click() Dim i, a, b, n As String n = InputB

16、ox(" 输入字符 ") i = Len(n)For a = 1 To i / 2b = Mid(n, a, 1)Mid(n, a, 1) = Mid(n, i + 1 - a, 1)Mid(n, i + 1 - a, 1) = bNext aPrint nEnd Sub17、利用随机函数生成一个4 X 4得矩阵(即二维矩阵),范围就是20,50内得整数,输出该矩阵所有数据之与Private Sub Form_Click()Dim a(3, 3), sum%For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 31 + 20)Nex

17、t jNext iFor i = 0 To 3For j = 0 To 3Print a(i, j);Next jPrintNext iFor i = 0 To 3For j = 0 To 3 sum = sum + a(i, j) Next jNext iPrint "sum=" sumEnd Sub18、编一子过程 Procmin(a(),amin) ,求一维数组中 a 得最小值 amin、 (随机产生 10 个 200-400 之间得数,并显示数组各元素;调用子函数,显示最小值) Private Sub Form_Click()Dim a(1 To 10), amin

18、, i%For i = 1 To 10 a(i) = Int(Rnd * 200 + 200) Print a(i);Next iCall s(a(), amin)PrintPrint "min=" aminEnd SubSub s(b(), min)Dim i% min = b(LBound(b)For i = LBound(b) + 1 To UBound(b)If b(i) < min Then min = b(i)Next iEnd Sub 19,20、编一个选择排序法子过程,对已知得若干整数按递增次序排列。 提示:子过程得形式为 sub sort1(a%()

19、。Private Sub Command1_Click()Dim b%(10), i%Print " 排序前 "For i = 1 To 10 b(i) = Int(Rnd * 100) Print b(i);Next iPrintPrint " 排序后 "Call sort(b()End SubSub sort(a%()Dim i%, m%, n%, min%, t% n = UBound(a)For i = 0 To n - 1min = iFor j = i + 1 To nIf a(j) < a(min) Then min = jNext

20、jm = a(i): a(i) = a(min): a(min) = mNext iFor i = LBound(a) To UBound(a)Print a(i);Next iEnd Sub递减次序排列Private Sub Command1_Click()Dim b%(10), i%Print " 排序前 "For i = 0 To 9b(i) = Int(Rnd * 100)Print b(i);Next iPrintPrint " 排序后 "Call sort(b()End SubSub sort(a%()Dim i%, m%, n%, min%

21、, j% n = UBound(a) For i = 0 To n - 1For j = 0 To n - 1 - iIf a(j) < a(j + 1) Then m = a(j): a(j) = a(j + 1): a(j + 1) = m Next jNext iFor i = LBound(a) To UBound(a) - 1Print a(i);Next iEnd Sub21,22、已知有序数组a(),编程插入x (x得值为14)。数组a中得元素分别 为 12 , 6, 4, 89, 75, 63, 100, 20 , 31。Ip = Val(InputBox("

22、请输入数字 x")For i = 0 To UBound(A)If Ip < A(i) ThenReDim Preserve A(UBound(A) + 1)t = A(i)A(i) = Ipins = iExit For End IfNext iFor i = ins + 1 To UBound(A) - 1 n = A(i)A(i) = tt = nNext iText2、 Text = ""For i = 0 To UBound(A) - 1Text2、 Text = Text2、 Text & " " & A(i)

23、Next iEnd SubPrivate Sub Form_Load()ReDim A(9)A(0) = 4: A(1) = 6: A(2) = 12: A(3) = 20A(4) = 31: A(5) = 63: A(6) = 75: A(7) = 89A(8) = 100End Sub23、声明一个整型得二维数组 a(1 to 4,1 to 4) ,用随机函数产生各元素, 范围介于 1,20之间, 编程将第 2 行与第 4 行对应元素交换。Private Sub Form_Click()Dim a(0 To 3, 0 To 3), i%, j%, tFor i = 0 To 3For j

24、= 0 To 3a(i, j) = Int(Rnd * 21 + 1)Print Tab(j * 5); a(i, j);Next jNext iPrintPrintFor j = 0 To 3t = a(1, j): a(1, j) = a(3, j): a(3, j) = t Next jFor i = 0 To 3For j = 0 To 3Print Tab(j * 5); a(i, j);Next jNext iEnd Sub24、定义三个4 X 4得二维数组A,B,C, A与B中得元素均随机生成,数组 A得范围就是1 20,数组B得范围就是100200,数组C就是A与B相加得到得。

25、请编程生成并输出 A,B,G Private Sub Command1_Click()Dim a(3, 3), b(3, 3), c(3, 3), t%, m%For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 20 + 1)Picture1 、 Print a(i, j);Next jNext iPicture1 、 PrintFor i = 0 To 3For j = 0 To 3 b(i, j) = Int(Rnd * 101 + 100) Picture1 、Print b(i, j); Next jNext iPicture1 、 Prin

26、tFor i = 0 To 3For j = 0 To 3 c(i, j) = a(i, j) + b(i, j) Picture1、Print c(i, j);Next jNext i25、随机产生 10 个 1100 得正整数放入数组,显示产生得数,求最大值、最小值、平均值。 Private Sub Form_Click()Dim a(1 To 10) As Integer, i%, maxa%, mina%, suma%For i = 1 To 10 a(i) = Int(Rnd * 71 + 30)Next imina = a(1)maxa = a(1)suma = a(1)For i

27、 = 2 To 10If a(i) > maxa Then maxa = a(i) If a(i) < mina Then mina = a(i) suma = suma + a(i)Next iFor i = 1 To 10Print a(i);Next iPrintPrint "max=" maxa, "min=" mina, "aver=" suma / 10 End Sub26、禾U用随机函数生成一个4 X 4得矩阵(即二维矩阵),范围就是20,50内得整数,输出每行中得最大值与下标。Dim a%(3, 3), i

28、%, j%, imax%Private Sub Command1_Click()For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 31 + 20) Picture1 、Print a(i, j); "" Next jPicture1 、 PrintNext i imax = 0For i = 0 To 3For j = 0 To 3If a(i, imax) < a(i, j) Then imax = jEnd IfNext jPicture2 、 Print "第" i + 1; "行&qu

29、ot; "最大值为 " a(i, imax); "下标为" "(" i; imax; ")"Next iEnd Sub27、声明一个整型得二维数组a(1 to 4,1 to 4),用随机函数产生各元素, 范围介于 1,20之间,编程将第 1 行与第 3 行对应元素交换。Private Sub Form_Click()Dim a%(1 To 4, 1 To 4), i%, j%Print " 排序前 "For i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd *

30、20 + 1)Print Tab(j * 4); a(i, j);Next jPrintNext iPrint " 排序后 "For j = 1 To 4t = a(1, j): a(1, j) = a(3, j): a(3, j) = tNext jFor i = 1 To 4For j = 1 To 4Print Tab(j * 4); a(i, j);Next jPrintNext iEnd Sub28、编写一个过程计算并输出区间100, 1000内所有素数得与(要求判断素数使用过程(函数或子过程)来实现) 。调用该过程。 (提示:只能被 1 与自身整除得自然数成为素

31、数) Function sushu%(ByVal x%)Dim m%, Tag As Boolean, i%m = Val(x)Tag = TrueFor i = 2 To m - 1If (m Mod i) = 0 Then Tag = False Next iIf Tag Then sushu = xEnd FunctionPrivate Sub Command1_Click()Dim i%, k%For i = 100 To 1000If sushu(i) Then List1、 AddItem iNext iSum = 0For k = 0 To List1、 ListCount -

32、1Sum = Sum + Val(List1、 List(k)Next kLabel1 = "100,1000内所有素数与为 :" & SumEnd Sub29,30、随机生成一个整型得二维数组,范围在10,20 之间,以下三角形式输出该数组。Private Sub Form_Click()Dim a(4, 4) As IntegerFor i = 0 To 4For j = 0 To 4a(i, j) = Int(Rnd * 11 + 10)Next jNext iFor i = 0 To 4For j = 0 To i Print a(i, j); Next j

33、 PrintNext iEnd Sub 以上三角形式输出该数组Dim a%(4, 4)Private Sub Command1_Click()Picture1 、ClsFor i = 0 To 4For j = i To 4Picture1 、Print Tab(j * 6); a(i, j);Next jPicture1 、PrintNext iEnd SubPrivate Sub Form_Load()For i = 0 To 4For j = 0 To 4 a(i, j) = Int(Rnd * 11 + 10)Next jNext iEnd Sub31、利用随机函数生成一个4X 4得矩

34、阵(即二维矩阵),范围就是40,80内得整数,求它得最大值及所对应得下标。Private Sub Form_Click()Dim a(3, 3), max%, imax%For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 41 + 40)Next jNext iFor i = 0 To 3For j = 0 To 3Print a(i, j);Next jPrintNext iFor i = 0 To 3For j = 0 To 3If max < a(i, j) Then max = a(i, j): imax = i & jNext

35、 jNext iPrint "max=" max; "imax=" imaxEnd Sub32、已知一维数组 a 中元素已排序,分别为 12,15,21,25,27,35,36,39,48,52, 编程将 30插入数组,使 a 仍保持有序。Private Sub Form_load()Dim a(), i%, k%, x%, n%a = Array(1, 4, 7, 9, 12, 14, 23, 56)n = UBound(a)For i = 0 To nList1、 AddItem a(i)Next iEnd SubPrivate Sub comman

36、d1_Click()x = Val(Text1)For k = 0 To List1、 ListCount - 1If x < Val(List1、 List(k) Then Exit For Next kList1、 AddItem x, kEnd Sub(做得时候一个命令控件、一个 text 文本框与一个 list)33、已知数组a(),编程删除a中第5个元素。数组a中得元素分别为12 , 6, 4 , 89, 75, 63, 100, 20, 31。Private Sub Form_Click()Dim a(), i%, n%a = Array(12, 6, 4, 89, 75,

37、63, 100, 20, 31)n = UBound(a)For i = 0 To nPrint a(i);Next iPrintFor i = 5 To n a(i - 1) = a(i) Next i n = n - 1ReDim Preserve a(n)For i = 0 To nPrint a(i);Next iPrintEnd Sub34、利用随机函数生成一个4X 4得矩阵(即二维矩阵),范围就是40,80内得整数,求它得最小值及所对应得下标。Dim a%(3, 3), i%, j%, imin%Private Sub Command1_Click()For i = 0 To 3F

38、or j = 0 To 3 a(i, j) = Int(Rnd * 21 + 40)Picture1、Print a(i, j); ""Next jPicture1 、PrintNext iimax = 0For i = 0 To 3For j = 0 To 3If a(i, imin) > a(i, j) Then imin = jEnd IfNext jPicture2、Print "第" i + 1; "行" "最小值为 " a(i, imin); " 下标为" "(&qu

39、ot; i; imin; ")"Next iEnd Sub1、找出被 3、5、7 除,余数 均为 1 得最小得 5个正整数。Private Sub Command1_Click()Dim countN%, n%countN = 0DoIf n Mod 3 = 1 And n Mod 5 = 1 And n Mod 7 = 1 ThenPrint ncountN = countN + 1End IfLoop Until countN = 5End Sub2、编程显示 100500之间所有得水仙花数之与。 (水仙花数就是 3位数,其各位数之与等于 该数本身 )Private S

40、ub Form_Click()Print "100500 之间所有得水仙花数为: "Dim x%, a%, b%, c%For x = 100 To 500 a = x Mod 10 b = (x Mod 100) 10c = x 100If x = a A 3 + b A 3 + c A 3 The n Print xNext xEnd Sub 3、输入一系列字符串,编程求出长度最大得字符串并输出其所对应得次序 Private Sub Form_Click()Dim a(5) As String, b(4) As Integer, t%, max%, imax%For i

41、 = 1 To 5a(i) = InputBox("a")Next iFor i = 0 To 4b(i) = Len(Trim(a(i)Next imax = 1For i = 0 To 4If max < b(i) Then max = b(i): imax = iNext iPrint "max=" a(i)Print "cixu=" imax + 1End Sub4、输入一系列字符串,将字符串按递减次序排列。请编程实现 Dim a() As String, n%, i%, j%Private Sub Command1_C

42、lick() n = Val(Text1)ReDim a(n) As StringFor i = LBound(a) To UBound(a)a(i) = InputBox("请输入字符串”)Picture1、Print a(i); Spc(1);Next iEnd SubPrivate Sub Command2_Click()For i = 0 To nFor j = 0 To n - 1If a(j) < a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = tNext jNext iFor i = 0 To nPictur

43、e2、Print Tab(3); a(i); Spc(1)Next iEnd Sub5随机产生 30100(包括 30、 100)中得十个正整数,求最大值、最小值、平均值,并显 示整个数组得值与结果。Private Sub Form_Click()Dim a(1 To 10) As Integer, i%, maxa%, mina%, avera!For i = 1 To 10a(i) = Int(Rnd * 71 + 30)Next imina = a(1)maxa = a(1)avera = a(1)For i = 2 To 10If a(i) > maxa Then maxa =

44、a(i) If a(i) < mina Then mina = a(i) avera = avera + a(i)Next iFor i = 1 To 10Print a(i);Next iPrintPrint "max=" maxa, "min=" mina, "aver=" avera / 10End Sub6、定义三个4 X 4得二维数组A,B,C, A与B中得元素均随机生成,数组 A得范围就是1 20,数组B得范围就是100200,数组C就是A与B相乘得到得。请编程生成并输出 A,B,Co Private Sub For

45、m_Click()Dim a%(1 To 4, 1 To 4), b%(1 To 4, 1 To 4), c%(1 To 4, 1 To 4)Print " 数组 A"For i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd * 20 + 1) Print Tab(j * 4); a(i, j);Next jPrintNext iPrint " 数组 B"For i = 1 To 4For j = 1 To 4b(i, j) = Int(Rnd * 100 + 100)Print Tab(j * 6); b(i, j);

46、Next jPrintNext i'Print " 数组 C"'For i = 1 To 4'For j = 1 To 4'c(i, j) = b(i, j) * a(i, j) 'Print Tab(j * 4); c(i, j);'Next j'Print'Next i Print " 数组 C"For i = 1 To 4For j = 1 To 4c(i, j) = b(i, j) * a(i, j)Print Tab(j * 6); c(i, j);Next jPrintNext

47、iEnd Sub7、随机产生 15 个小写字母,放在字符串中。 (提示: c=chr(int(rnd*26+97) ) Private Sub Form_Click()Dim a$(1 To 15), i%Print " 字符数组为 a(i):"For i = 1 To 15 a(i) = Chr(Int(Rnd * 26 + 97)Print a(i); Spc(1);Next iPrintEnd SubPrivate Sub Form_Load()FontSize = "10"End Sub&利用随机函数生成一个4X 4得矩阵(即二维矩阵),

48、范围就是20,50内得整数,求它得两条对角线上元素之与。Private Sub Command1_Click()Dim a%(3, 3), i%, j%, sum%For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 31 + 20)Picture1 、Print a(i, j); ""Next jPicture1 、 PrintNext isum = 0For i = 0 To 3 sum = sum + a(i, i) + a(i, 3 - i) Next iText1 = sumEnd Sub9、有 10 个评委对歌手进行打分

49、(分数存放在A 数组中)要求编程计算歌手平均得分(按去掉一个最高分与一个最低分得计算办法计算)Private Sub Form_Click()Dim a(), max%, min%, imax%, imin%, s!a = Array(98, 97, 95, 91, 90, 99, 93, 94, 93, 96)n = UBound(a)For i = 0 To nPrint a(i);Next iPrint min = a(0): imin = 0 For i = 0 To nIf a(i) < min Then min = a(i): imin = i Next iPrint &qu

50、ot;min=" min; "imin=" iminFor i = imin + 1 To na(i - 1) = a(i)Next iReDim Preserve a(n - 1)For i = 0 To n - 1Print a(i);Next iPrintFor i = 0 To n - 1If a(i) > max Then max = a(i): imax = i Next iPrint "max=" max; "imax=" imaxReDim Preserve a(n - 2)s = 0For i = 0 To n - 2s = s + a(i) Print a(i);Next iPrintPri

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论