BB平台VB程序匹配题_第1页
BB平台VB程序匹配题_第2页
BB平台VB程序匹配题_第3页
BB平台VB程序匹配题_第4页
BB平台VB程序匹配题_第5页
免费预览已结束,剩余54页可下载查看

下载本文档

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

文档简介

1、保存问题32.25分从键盘输入一段英文文章(都是小写字母),统计一下该段文章中26 个英文字母的使用情况。Private Sub Form_Click()Dim c(1 To 26) As IntegerDim n As In teger, k As In tegerDim s As String, xs As StringFor i = 1 To 26c(i) = 0Next i(2)For i = 1 To n(3)If xs >= "a" And xs <= "z" Then(4) (5) End IfNext iFor i = 1 T

2、o 26Pri nt Chr(96 + i); "-" c(i)Next iEnd Sub1. n = Len(s)2. c(k) = c(k) + 13. k = Asc(xs) -964. s = In putBox("s=")5. xs = Mid(s, i, 1)问题42.25分单击窗体,产生20个从1到600之间的随机整数,并以每行5个把数据显示在窗体上,并在窗体上显示20个数据中的所有偶数之和。保存Private Sub Form_Click()(1)For i = 1 To 20Ran domizePrint x;(3)If (4) The

3、 n s = s + xNext i(5)End Sub2.(1)5.寸2)1. If i mod 5 =0 The n Print2. Dim i As In teger, x AsIn teger, s as Long3. Prin t "s=" s4. x Mod 2 = 05. x = In t(600*R nd+1)4问题5实现文本框的复制、剪切、粘贴、删除功能2.25 分保存Private Sub Comma nd1_Click()Clipboard.SetText Text1.SelTextEnd SubPrivate Sub Comma nd2_Click(

4、)Clipboard.ClearEnd SubPrivate Sub Comma nd3_Click()(4)End SubPrivate Sub Comma nd4_Click()End Sub1. Text1.SelText =""2. Textl.SelText =""3. Textl.SelText =Clipboard.GetText4. Clipboard.Clear5. Clipboard.SetTextTextl.SelText问题62.25 分调用VB的RND和INT函数,在当前工作表的 A列的1 TO行输入序号 1 T0,B列的1 0

5、行填入0 之间的随机数,C列的1 T0行填入两 位正整数,最后在 C列的11行求出该列的最大数(调用 EXCEL的内部 MAX函数)。Sub ran dom()Dim i As In teger, c As StringFori = 1 To 10Next iFori = 1 To 10Ran ge(c) = RndNext iFori = 1 To 10c = "C" & i(4)Next iEnd Sub(4)1 c = "B" & i2 Range(c) = i3 Range("C11")=.Applicatio

6、n.WorksheetFunction.Max(Range("C1:C10")4 Range(c) = Int(Rnd * 90) + 105 c = "A" & i问题72.25分保存编制Form_Click过程,用近似公式求自然对数的底数e的值,直到末项小于10-4为止,结果显示在窗体上。Private Sub Form_Click()Dim s As Sin gle, x As Si ngle, a As Sin glea = 1i = 1Do (2)(3(5)LoopEnd Sub保存1. While a >= 0.00012. P

7、rin t "e=" s3. s = s + a4. a = a / i5. s = 1问题82.25分从键盘输入一个字符串,然后将该字符串中的每个字符按ASCII码值的大小从小到大进行重新组合输出。如:输入abc123XYZ,处理后应输出123XYZabc。(难度系数*)Private Sub Form_Click()Dim c(100) As Stri ngDim n As In tegerDim s As String, nc As Str ing, temp As String s = In putBox("s=")For i = 1 To nN

8、ext i(2)For i = 1 To n - 1For j = i + 1 To nc(i) = c(j)c(j) = tempEnd IfNext jNext inc =""For i = 1 To n(5)Next iPrint nc(1)End Sub1. nc = nc & c(i)2. temp = c(i)3. If c(i) > c(j) Then4. n = Len(s)5. c(i) = Mid(s, i, 1)保存问题92.25分利用二维数组编程输出“杨辉三角形”图案,图案行数n从键盘输入。Private Sub Form_Click(

9、)Dim x() As In tegerDim n As In tegerFor i=2 To nFor j=1 To iNext jNext iFor i=1 To nFor j=1 To iPri nt x(i,j);Next j(5)Next i(1)End Sub1. Print2. Redim x( n,n)3. n = In putBox(" n=")4. x(i,j) = x(i-1,j) + x(i-1,j-1)5. x(1,1)=13.保存问题102.25分随机产生100个学生的成绩(3598之间),统计各分数段的人数。即 09、1019、2029、303

10、9、4049、5059、6069、 7079、8089、9099,并输出结果。Private Sub Form_Click()Dim a(1 To 100) As In teger(1)For i = 1 To 100Next iFor i = 0 To 9c(i) = 0Next ic(k) = c(k) + 1Next i(5)Print 10*i;""10*i+9;"-"c(i)Next iEnd Sub1. Fori = 1 To 1002. For i = 0 To 93. Dim c(9) As Integer4. k = In t(a(i)

11、 / 10)5. a(i) = Int(Rnd * 64)+35保存问题112.25分建立一个“猜数程序”。单击窗体,产生一个2位的随机正整数。在文本框Textl中输入你猜测的数字,单击按钮Command1在窗体 上显示猜测结果:如果你输入的数字比程序生成的随机数要大,则 显示“大了”;如果比程序生成的随机数要小则“小了”;然后继 续输入数字进行猜测。如果猜中,则显示“恭喜你猜中啦!”,并 用消息框显示一共猜了几次。Dim n As In teger, k As In tegerRan domizeEnd SubPrivate Sub Comma nd1_Click()Dim x As In

12、teger(3)If x > n The nPrint x;"大了 "Print x;"小了 "ElsePrint x;"恭喜你猜中了!"MsgBox "共猜了 " & k & "次"End If(5)1. n = In t(R nd * 90) + 102. Private SubForm_Click()3. ElseIf x < n The n4. End Sub5. x = Text1.Text保存问题122.25分单击窗体,从输入框InputBox输入x和n,

13、并计算下列表达式的值,直至末项小于 为止,结果显示在窗体。Private Sub Form_Click()Dim s As Single, x As Single, a As Singlex = Val(InputBox("输入 x")s = 1i = 0Do(s = s + a(4)Loop(3)问题132.25 分保存从1到10000中找出这样的数,该数各个位的数字的阶乘相加之和 等于该数,并将结果输出。已知fact函数用于计算阶乘。Private Fun cti on fact(ByVal k As In teger) As LongDim i As In teger

14、Fori = 2 To kfact = fact * iNext iEnd Fun cti onPrivate Sub Form_Click()Dim k as integer,a as string,n as long, i as integerDim p As In tegerEnd SubJTiX X K _ X ,S = 1 + +4+K 牛+ 代23141刚1. i = i + 12. a = a * x / i3. Prin t "s=" s4. While a >= 0.000015. a = 1For k = 1 To 10000n = 0For i=

15、 1 To Len(a)Next i(5)Next kEnd Sub1. fact = 12. If n = k Then Print k3. n = n + fact(p)4. p = Val(Mid(a, i, 1)5. a = CStr(k)保存问题142.25分输入10个数放入数组中,将第1个数移到最后位置,其余数依次往 前移动一个位置。Private Sub Form_Click()Dim t As In tegerFori = 1 To 10(1)Next iFori = 1 To 10Print x(i);Next iPrintFor i = 1 To 10-1Next ix(1

16、0) = tFori = 1 To 10(5)Next iPrintEnd Sub1. Dim x(10) As In teger2. x(i) = In putBox("x("& ")=")3. Print x(i)4. t = x(1)5. x(i) = x(i+1)问题152.25 分保存随机产生200个互不相等的三位正整数并按每10个一行输出Private Sub Form_Click()Dim a(200) As In tegerDim k As In teger,x As In tegerDim f As In tegerDo Whi

17、le k<200x = In t(R nd*900)+100f=1For i=1 To kIf a(i)=x Then (2)Next iIf f=1 The n(3) (4) End ifLoopFor i=1 To kPrint a(i);(5)Next iEnd Sub(1)1. k=k+12. f=05.3. a(k)=x4. If i Mod 10=0 Then Print5. k=0保存问题162.25分随机产生10个6TOO之间的偶数,对每个数进行哥德巴赫猜想 (Goldbach Conjecture )验证。其中判断一个整数是否为素数 用以下Prime函数。Fun cti

18、 on Prime(x As In teger) As Boolea nDim i As In tegerPrime = TrueFor i = 2 To x - 1If x Mod i = 0 ThenPrime = FalseExit ForEnd IfNext iEnd Fun cti onSub Goldbach()Dim i As In teger, a As In teger, b As In tegerActiveSheet.Cells.ClearCells(1, 1) = ">6的偶数"Cells(1,2)="第一个素数"(1)Fo

19、ri = 1 To 10(?)Next iFor i = 2 To 11(3)If Prime(a) And Prime(Cells(i, 1) - a)The n(4) (5) Exit ForEnd IfNext aNext iEnd SubAC.1M的偶数第一不謙数第二个素数98195314t 623595,6S76153137._ 223198'403创g763731094589113791. Cells(1, 3)="第二个素数“2. Cells(i, 2) = a3. For a = 3 To Cells(i, 1) / 24. Cells(i, 3) = Cel

20、ls(i,1) - a5. Cells(i + 1, 1)=(Int(Rnd * 48) + 3) * 2问题172.25分单击窗体,根据输入框所输入的百分制成绩score,在窗体上显示相应的等级,即"优秀"(score>=90)、"良好"(80<=score<90)、“中” (70<=score<80)、“及格” (60<=score<70)、“不及格”(score<60) 。保存Private Sub Form_click()(1)score = Val( In putBox("If (2)

21、The nPrint "优秀"请输入成绩")ElseIf score >= 80 ThenPrint "良好"Elself score >= 70 ThenPrint "中"ElsePrint "不及格"(5)End Sub1. Print " 及格"2. End If3. ElseIf score >= 60 Then4. Dim score As In teger5. score >= 90保存问题182.25分单击窗体,从输入框InputBox 输入一个整

22、数,判断其是否为素数。 例如输入7,贝V屏幕上显示“ 7是素数”;如果输入的是 9则屏幕上 显示“ 9不是素数”。Private Sub Form_Click()Dim i As In teger, n As In teger, Prime As String n = Val(I nputBox(" n=")If n < 2 The nElse(1)If n Mod i = 0 Then Exit ForNext i(3) ElsePrime ="不是素数”End IfEnd If(1)End Sub1. Prime ="不是素数"2.

23、For i = 2 To n-13. If i > n-1 The n4. Print n & Prime问题1915. Prime =" 是素数"2.25 分、在文本框Text1中输入一个正整数,单击按钮Command1,判断该数的奇偶性,结果显示在标签框Iabel2中,要求偶数用蓝色显示,奇数用红色显示。Private Sub Comma nd1_Click()Dim x As In tegerIfThe nLabel2.ForeColor = vbBlue(3)(4)(5)Label2.Caption = x & "是奇数"E

24、nd IfEnd Sub保存1. x Mod 2 = 02. Else3. Label2.ForeColor = vbRed4. x = Val(Text1.Text)5. Label2.Caption = x & ”是偶数”问题202.25分编写程序,在工作表上打印九九乘法表如下。Sub prin t99()Dim i As In teger, j As In tegerFori = 1 To 9Cells(1, i + 1) = iCells(i + 1,1) = iNext i(2)(3)(4) Next jNext iRan ge("A:A").Fo nt.

25、Bold = TrueRan ge("A:A").Horiz on talAlig nment = xlCe nter(5)r1 (2)Ran ge("1:1").Horizo ntalAlig nment = xlCe nterEnd SubARcriEGHIJ11234567S92112345678932468101214161843$12151321242754162024283236652530354045763642魏5487495663g8647210981113. For i = 1 To 94. ActiveSheet.Cells.Cle

26、ar5. For j = i To 9保存R2.- (4)1. 问题212.25分在工作表1上创建“控件工具箱”命令按钮“产生数据”(CommandButton1 )和“判断"(CommandButton2 )。单击“产生数据”按钮完成在A1 : A10上产生两位随机正整数;单击“判 断”按钮完成将其中重复数用红色标注。Private Sub Comma ndButto n1_Click()Dim i As In tegerFori = 1 To 10(2)Next iEnd SubPrivate Sub Comma ndButto n2_Click()Dim i As In teg

27、er, j As In tegerFori = 1 To 9(3)(4) End IfNext j(5)Next iEnd Sub保存1. For j = i + 1 To 102. If Cells(i, 1) = Cells(j,1) The n3. ActiveSheet.Cells.Clear4. Cells(i, 1) = Int(Rnd *90) + 105. Cells(j,1).Fo nt.ColorvbRed问题222.25分从文本框Text1输入一个二进制正整数,单击窗体,在窗体上打印 出相应的十进制数;且文本框中只允许输入0和1。Private Sub Form_Clic

28、k()Dim s As String, a As String, n As In teger, x As Longn = Len(s)For i = 1 To nx = x + Val(a) * 2 A (i - 1)Next i(3)End SubPrivate Sub Text1_KeyPress(KeyAscii As In teger)If (4) Then(5)End IfEnd Sub1. KeyAscii < Asc("0") OrKeyAscii > Asc("1")2. Print x3. KeyAscii = 04. s

29、= Text1.Text5. a = Mid(s, n + 1- i, 1)保存问题232.25分随机产生两位数的整数放入一个5行5列的二维数组中,求该二维数组对角线上最大值所在的行和列。Private Sub Form_Click()Dim a(1 To 5, 1 To 5) As In teger, max As In tegerDim pi As In teger, pj As In tegerRan domizeForj = 1 To 5For i = 1 To 5a(i, j) = In t(R nd * 90 + 10)Next jNext iFor i = 1 To 5Forj

30、= 1 To 5Print a(i, j);Next j(1)Next imax = a(1, 1)(2)Pj = 1For i = 1 To 5Forj = 1 To 5(3)(4)max = a(i, j)pi = i(5) End IfEnd IfNext jPrint "对角线上最大值在第"pi;"行和第"pj;"列"End Sub1. pi = 12. If i = j Or i + j = 6 Then3. pj = j4. Print5. If max < a(i, j) Then问题242.25分产生10个30

31、, 50的随机整数,并按从小到大的顺序打印出来, 要求调用Swap子过程。保存Public Sub Swap(a As In teger, b As In teger)Dim temp As In teger temp = a(1)End SubPrivate Sub Form_Click()Dim a(10) As In tegerDim i As In teger, j As In teger a(i)= In t(R nd * 21) + 30Fori = 1 To 10Next iFori = 1 To 9For j = i + 1 To 10If a(i) > a(j) The

32、nEnd IfNext jNext i(5)End Sub1. Call Swap(a(i), a(j)2. a = b3. b = temp4. Form1.pri nt a(10)5. Form1.Print a(i);问题252.25 分输入n后,再输入n个数a1 , a2 , ., an ,按照下列公式计算s的值并显示。已知求 v值的函数过程f程序如下。编写事件过程Command1_Click() ,计算s值,其中v值要求调用函数过程f 来完成。Private Function f (x() As Sin gle, n As In teger) as sin gleDim i As I

33、n tegerFor i = 1 To nNext iEnd FunctionPrivate Sub Comma nd1_Click()Dim a() As Single, n As Integer, s As SingleDim v As Si ngle, i As In tegern = InputBox("请输入n的值")For i =:1 To na(i)=In putBox("")Next iFor i =:1 To ns =s + (a(i) - v) A 2Next iPrint sEnd Sub&1+七+叫_ vV十(勺_ V)十

34、十玉_访V = S 1. f=f / n2. ReDim a(n)3. f = f + x(i)4. s = Sqr(s) / n5. v = f(a, n)问题262.25分验证哥德巴赫猜想一才于6的偶数可以分解为两个素数之和,通过调用函数过程实现判断任一输入的正整数是不是素数。保存PrivateFun cti onprime(ByVal n As In teger)As Boolea nDim i As In teger(1)For i = 2 To Sqr( n)Next iEnd Fun cti onPrivate Sub Form_Click()Dim n1 As Integer,

35、n2 As Integer, n As IntegerDon = InputBox("输入一个大于 6的偶数")Loop While n <= 6 Or n Mod 2 <> 0For n1 = 3 To n / 2 Step 2(3)(5)Exit ForEnd IfNext n1End Sub保存1. If n Mod i = 0 Then prime=False: Exit For2. If prime (n1) Andprime( n2) Then3. n2 = n - n14. Print n; "="n1; "+&

36、quot; n25. prime = True问题272.25分单击窗体,实现以下的分段函数,其中x从输入框输入,求出 y显示在窗体上。Private Sub Form_Click()If x < -5 The ny = x * Sin (x) + 2 a xElsey = Sqr(x - 5) + Log(x) / Log(10)(5)End Sub3ja + 2x 1x < -5 sin x + 2-5 <= 2; <= 57-5 4-log w x>51. Print y请输入2. x = Val(l nputBox("x")3. Dim

37、 x As Si ngle, y AsSi ngle4. End If5. Elself x <= 5 The n保存问题282.25分从键盘输入一批英文字母并逐个放入数组中,然后将其中的大写字 母转换为小写字母,小写字母转换为大写字母并输出。Private Sub Form_Click()Dim a() As Stri ngDim s As String, ns As StringDim n As In tegers = In putBox("s=")n = Len(s)For i = 1 To n(2)Next iFor i = 1 To nIf a(i) >

38、;= "A" A nd a(i) <= "Z" The n(3Else(4)End IfNext iFor i = 1 To n(5)Next iPrint sPrint nsEnd Sub1. a(i) = Mid(s, i, 1)2. ReDim a(n)3. a(i) = Chr(Asc(a(i)-32)4. ns = ns + a(i)5. a(i) = Chr(Asc(a(i) +32)保存问题292.25分从输入框InputBox输入n,再从输入框输入这n个整数,要求以每行5个的形式输出这n个数(其中的偶数用红色显示),计算它vbBla

39、ckPrivate Sub Form_Click()Dim n As In teger, x As In teger, ave As Sin gle, sAs Si nglen = Val(l nputBox(" n")For i = 1 To n(1)If x Mod 2 = 0 The n(Else(3)End IfPrint x;(4)s = s + xNext i(5)PrintPrint "平均值为:"& aveEnd Sub1. ave = s / n2. If i Mod 5 = 0 Then Print3. x = Val(I n

40、putBox("x")4. Forml.ForeColor =5. Forml.ForeColor = vbRed保存问题302.25分随机产生25个三位正整数,用选择排序法按从大到小顺序输出。Private Sub Form_Click()Dim a(1 To 25) As In tegerDim t As In tegerFor i = 1 To 25(1)Print a(i);Next iPrint(2)(3)(4)t = a(i)(5)a(j) = tEnd IfNext jNext iFor i = 1 To 25Print a(i);Next iPrintEnd

41、 Sub1. a(i) = Int(Rnd * 900) +1002. If a(i) > a(j) The n3. For i = 1 To 244. For j = i + 1 To 255. a(i) = a(j)问题312.25分求下面表达式的值,并在窗体上输出。要求m与n的值在窗体单击事件中用Inputbox() 函数输入,且同为正整数, m>n。通过函数 过程实现求阶乘的功能。保存(1)Dim i As In tegerFori = 2 To k(3)Next iEnd Fun cti onPrivate Sub Form_Click()Dim m As In tege

42、r, n As In tegerDom = In putBox("m=", "m>0,m必须大于n")n = In putBox(" n=", "n >0")(5)(1)End Sub1. Print fact(m) / fact( n)/ fact(m - n)2. Private Functionfact(ByVal k As Integer)As Long3. Loop While m <= n Or m <0 Or n < 04. fact = fact * i5. fact

43、= 1保存问题322.25分编程,在窗体上显示单击窗体的次数。第一次单击时,窗体上以红 色显示“第1次单击窗体”;第二次单击时,窗体上以蓝色显示“第 2次单击窗体”;第三次单击时,窗体上以绿色显示“第3次单击窗体”,第四次单击时,清除窗体上的信息。第五次单击的效果和 第一次一样,以此类推,运行效果如图所示。Private Sub Form_Click()(2)If n = 1 The nForm1.ForeColor = vbRedPrint "第1次单击窗体"ElseIf n = 2 The n(3)Print "第2次单击窗体"Elself n =

44、3 The nForml.ForeColor = vbGree nElself n = 4 The nForml.CIs(5)End IfEnd Sub.3T3第1次单击窗体 第茁欠单击窗体 謫体(1)保存1. n = n + 12. n = 03. Forml.ForeColor =vbBIue4. Dim n As In teger5. Print " 第3次单击窗体”问题332.25分单击窗体,从键盘输入三个数,将它们从大到小输出在窗体上。Private Sub Form_Click()Dim x As Si ngle, y As Sin gle, z As Sin glex

45、= Val(l nputBox("x")z = Val(l nputBox("z")If x < y The nEnd IfIf x < z The nEnd Ift = y: y = z: z = tEnd If(5)End Sub1. Print x, y, z2. t = x: x = z: z = t3. y = Val(I nputBox("y")4. If y < z The n5. t = x: x = y: y = t保存问题342.25分单击窗体,输出下列数字图案(行数从输入框In putBox 输

46、入)。Private Sub Form_Click()Dim n As In teger(2)Forj = 1 To nIf j < i The n(3) Else(4) End IfNext j(5) Next iEnd Sub(1)1. Print请输入行数2. n = In putBox("")3. For i = 1 To n4. Print j - i + 1;5. Print n + 1- j;1. 保存问题352.25分建立一个n行n列的二维数组,n从键盘输入,数组元素值由随机 函数产生10,99 之间的正整数,求该数组对角线上各元素的平均 值。Priv

47、ate Sub Form_Click()Dim a() As In tegerDim i As In teger, j As In tegerDim s As Si ngle, v As Si ngleDim n As In tegern = In putBox(" n=")ReDim a(n, n)s = 0For i = 1 To nForj = 1 To na(i, j) = In t(R nd * 90 + 10)(1)(2)For i = 1 To nForj = 1 To nPrint a(i, j);Next jPrintNext iFor i = 1 To

48、nForj = 1 To nNext jNext iIf n Mod 2 = 0 The nElseEnd IfPrint "v=" vEnd Sub(1)1. Next j2. v = s / (2 * n - 1)3. Next i4. v = s / (2 * n)5. If i = j Or i + j = n +1 The n s = s + a(i, j)问题362.25 分保存单击窗体,从输入框输入一个字符串,判断其是否为“回文”并在 窗体上打印结果。“回文”是指字符串顺读与倒读都是一样的,如 “潮起潮落,落潮起潮”。Private Sub Form_Clic

49、k()Dim s As String ,n as Integers = InputBox("请输入字符串")For i = 1 To n 2If (2) Then(3)End IfNext iIf i <= n 2 ThenElse(5)End IfEnd Sub1. Print s & ”不是回文”2. Print s & ”是回文”3. Mid(s, i, 1) <> Mid(s, n+ 1 - i, 1)4. n = Len(s)5. Exit For保存问题372.25分分别在两个文本框中输入年和月份,单击命令按钮Comma nd1在标签框Iabel3中显示该月天数(注意闰年的情况。闰年的判断条件为:年份能被4整除但不能被100整除,或者能被400整除)。Private Sub Comma nd1_Click()Dim y As In teger, m As In tegery = Va

温馨提示

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

评论

0/150

提交评论