2022年最容易考到的vb程序设计 .pdf
第 1 题:编程,用随机函数产生2 个 10100 的整数,输出最大值。正确答案:Private Sub Command1_Click() Dim x%, y%,max% Randomize x = Int(Rnd * 91 + 10) y = Int(Rnd * 91 + 10) Max = x If y Max Then y = Max Print Max End Sub 第 2 题:编程,将一个三位整数倒序输出。Private Sub Command1_Click() Dim x%, bw%, sw%, gw% x = Text1.Text bw = x 100 整除 Mod 取余gw = x Mod 10 x = gw * 100 + sw * 10 + bw Print x End Sub 第 2 题:编程,求算式1+1/2!+1/3!+1/4!+前 10 项的和。正确答案:Private Sub Command1_Click() Dim i%, s!,a! a = 1: s = 0 For i = 1 To 10 a = a / i s = s + a Next i Print 1+1/2!+1/3!+=; s End Sub 第 1 题:编程,求方程x2+y2=1000的所有整数解。正确答案:Private Sub Command1_Click() Dim x%, y% For x = -32 To 32 For y = -32 To 32 If x 2 + y 2 = 1000 Then Print x, y End If 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 6 页 - - - - - - - - - Next y, x 或 Next y Next x (先 y 后 x) 因为两个 for End Sub 第 1 题:编程,求算式1-1/2+1/3-1/4+前 30 项的和。正确答案:Private Sub Command1_Click() Dim i%, s!, f% s = 0: f = 1 For i = 1 To 30 s = s + f / i f = -f Next i Print 1-1/2+1/3-1/4+=; s End Sub 第 3 题:编程,计算多项式Sn=a+aa+aaa+aaaa+ +aaa(n 个 a) ,其中 a 是一个随机产生的 19 之间的整数; n 是一个 510 之间的整数可从输入对话框中输入。正确答案:Private Sub Form_Click() Dim i%, a#, n%, s# Randomize a = Int(Rnd * 9) + 1 Do n = InputBox(输入一个 n 值:) Loop While n 10(运行一下 ) s = 0 For i = 1 To n T= T + a s = s + T a = a * 10 错的,应该还有 b=a Next i Print s=a+aa+aaa+; s End Sub 第 2 题:编程,打印输出有数字组成的金字塔。图案如图所示。(P67) 1 222 33333 4444444 555555555 4444444 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 6 页 - - - - - - - - - 33333 222 1 正确答案:Private Sub Form_Click() Dim i%, j%, k% For i = 1 To 5 Print Tab(1+5 - i); 设置该行输出的起始位置For j = 1 To 2 * i - 1 Print Trim(Str(i); Next j Print Next i For i = 4 To 1 Step -1 Print Tab(1+5 - i); For j = 1 To 2 * i - 1 Print Trim(Str(i); Next j Print Next i End Sub 数组:第 1 题:编程,从键盘输入一个字符串,将该字符串中的各个字符按照ASCII 码从小到大排序后组成新的字符串,再从窗体输出。例如:输入字符串为“A4ngZ9 ” ,输出字符串为“49AZgn ” 。正确答案:Private Sub Form_Click() Dim a() As String Dim x$, i%, n%, p% x = InputBox( 输入一个字符串) n = Len(x) ReDim a(n) For i = 1 To n a(i) = Mid(x, i, 1) Next i For i = 1 To n p = i For j = i + 1 To n If a(j) 1 If a(n) find Then find = a(n) n = n - 1 Wend End Function 第 1 题:编写一个过程,功能为在同一行输出n 个数字字符。正确答案:Private Sub pp(n As Integer, x As Integer) Dim i% For i = 1 To n Print x; Next i End Sub 第 1 题:编写一个过程,功能为在同一行输出n 个“ *” 。正确答案:Private Sub pp(n As Integer) Dim i% For i = 1 To n Print *; Next i End Sub 第 1 题:编一个 SUB 过程,其功能为: 对一个一维数组a(n)的各个元素, 分别统计 90 以上,80 89,7089, 6979,6069,60 以下各数段个数。正确答案:Private Sub Ncount(a() As Integer, n As Integer, b() As Integer, m As Integer) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 6 页 - - - - - - - - - Dim i As Integerr For i = 1 To n Select Case a(i) Case Is 89 b(1) = b(1) + 1 Case 80 To 89 b(2) = b(2) + 1 Case 70 To 79 b(3) = b(3) + 1 Case 60 To 69 b(4) = b(4) + 1 Case Else b(5) = b(5) + 1 End Select Next i End Sub 第 1 题:编写一个函数,其功能是求n。正确答案:Private Function sum(n As Integer) As Single Dim i% sum = 0 For i = 1 To n sum = sum + i Next i End Function 第 1 题:编写一个函数,其功能是求n!。正确答案:Private Function jc(n As Integer) As Single Dim i% jc = 1 For i = 1 To n jc = jc * i Next i End Function 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 6 页 - - - - - - - - -