版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 问题 1 得 2.22 分,满分 20 分 编写一子过程,将数组a(n, n)转置。 正确答案所选答案1. Public Sub ff(a() As Single, n As Integer) 1.Public Sub ff(a() As Single, n As Integer) 2. Dim i As Integer, j As Integer, t As Single -未给定 3. For i = 2 To nFor j = 1 To i-1-未给定 4. t = a(i, j) -未给定 5. a(i, j) = a(j, i) -未给定 6.
2、a(j, i) = t -未给定 7. Next j -未给定 8. Next i -未给定 9. End Function -未给定 问题 2 得 0 分,满分 20 分 求下面表达式的值,并在窗体上输出。要求m与n的值在窗体单击事件中用Inputbox()函数输入,且同为正整数,m>n。通过函数过程实现求阶乘的功能。 Private Sub Form_Click() Dim m As Integer, n As Integer Do m = InputBox(&quo
3、t;m=", "m>0,m必须大于n")n = InputBox("n=", "n>0") Loop While m <= n Or m < 0 Or n < 0 Print fact(m) / fact(n) / fact(m - n)End Sub 正确答案所选答案1. Private Function fact(ByVal k As Integer) As Long -未给定 2. Dim i As Integer -未给定 3. fact
4、= 1 -未给定 4. For i = 2 To k -未给定 5. fact = fact * i -未给定 6. Next i -未给定 7. End Function -未给定 问题 3 得 0 分,满分 20 分 编写一个将一维数组倒置存放的子过程,并编写简单事件验证子过程的正确性。 Private Sub Form_Click()Dim b(6) As SingleFor i = 1 To 6 b(i) = InputBox(“b(” + Str(i) + “)=”) Print b(i
5、),Next IPrintCall rev(b(), 6) For i = 1 To 6 Print b(i), Next iEnd Sub 正确答案所选答案1. Public Sub rev(x() As Double, n As Integer) -未给定 2. Dim i As Integer, t As Double -未给定 3. For i = 1 To n 2 -未给定 4. t = a(i): a(i) = a(n - i + 1): a(n - i + 1) = t -未给定 5. Next i -未给定 6.
6、End Sub -未给定 问题 4 得 0 分,满分 20 分 输入n后,再输入n个数a1 ,a2 ,.,an ,按照下列公式计算s的值并显示。 编写事件过程Command1_Click(),计算s值,其中 v 值要求调用函数过程 f 来完成。已知求v值的函数过程 f程序如下。Private Function f (x() As Single, n As Integer) as single Dim i As Integer For i = 1 To n f = f + x(i)
7、; Next i f = f / nEnd Function 正确答案所选答案1. Private Sub Command1_Click() -未给定 2. Dim a() As Single, n As Integer, s As SingleDim v As Single, i As Integer-未给定 3. n = InputBox("请输入n的值")ReDim a(n)-未给定 4. For i = 1 To n -未给定 5. a(i) = InputBox("") -未给定 6. Next iv = f
8、(a, n)-未给定 7. For i = 1 To n -未给定 8. s = s + ( a(i) - v ) 2 -未给定 9. Next i -未给定 10. s = Sqr(s) / n -未给定 11. Print s -未给定 12. End Sub -未给定 问题 5 得 0 分,满分 20 分 编写Sub过程求一元二次方程的实数解,并通过事件过程调用它。 Private Sub Command1_Click() Dim a As Double, b As Double, c As Double, y1 A
9、s Double, y2 As Double a = 3: b = 1: c = 5 If root(a, b, c, y1, y2) Then Print y1, y2 Else Print "方程无实数解!" End IfEnd Sub 正确答案所选答案1. Private Function root(ByVal a As Double, ByVal b As Double, ByVal c As Double, x1 As Double, x2 As D
10、ouble) As Boolean -未给定 2. Dim d As Double -未给定 3. d = b * b - 4 * a * c -未给定 4. If d < 0 Then -未给定 5. root = False -未给定 6. Else -未给定 7. root = Truex1 = (-b + Sqr(d) / (2 * a): x2 = (-b - Sqr(d) / (2 * a)-未给定 8. End If -未给定 9. End Function -未给定 问题 1 得 0 分,满分 20 分 编写一子过程,将数组a(n, n)转置。
11、正确答案所选答案1. Public Sub ff(a() As Single, n As Integer) -未给定 2. Dim i As Integer, j As Integer, t As Single -未给定 3. For i = 2 To nFor j = 1 To i-1-未给定 4. t = a(i, j) -未给定 5. a(i, j) = a(j, i) -未给定 6. a(j, i) = t -未给定 7. Next j -未给定 8. Next i -未给定 9. End Function -未给定 问题 2 得 0 分,满分 20 分
12、60; 两质数的差为2,称此两质数为质数对,设计一个程序找出100以内的质数对,并在窗体上成对显示结果。要求质数的判断用自定义函数完成。 正确答案所选答案1. Private Function prime(ByVal k As Integer) As Boolean -未给定 2. Dim i As IntegerIf k < 2 Then -未给定 3. prime = False -未给定 4. Else -未给定 5. For i = 2 To Sqr(k) -未给定 6. If k Mod i = 0 Then Exit For -未给定 7. Next iIf i
13、> Sqr(k) Then prime = True Else prime = False-未给定 8. End If -未给定 9. End FunctionPrivate Sub Form_Click()-未给定 10. Dim n As Integer -未给定 11. For n = 3 To 100 Step 2 -未给定 12. If prime(n) And prime(n + 2) Then Print n; n + 2 -未给定 13. Next n -未给定 14. End Sub -未给定 问题 3 得 0 分,满分 20 分
14、编写子过程,将某数组中元素按值从大到小排序,并在窗体的单击事件中,编写简单程序验算其正确性。 Private Sub Form_click() Dim x(10) As Single, i As Integer Print "排序前:" For i = 1 To 10 x(i) = InputBox("b(" + Str(i) + ")=") Print x(i); Next i Pri
15、nt Call sort(x(), 10) Print "排序后:" For i = 1 To 10 Print x(i); Next iEnd Sub 正确答案所选答案1. Private Sub sort(a() As Single, ByVal n As Byte) -未给定 2. Dim i As Byte, j As Byte, k As Byte, temp As Single -未给定 3. For i = 1 To n - 1 -未给定 4. k = i
16、 -未给定 5. For j = i + 1 To n -未给定 6. If a(j) > a(k) Then k = j -未给定 7. Next j -未给定 8. temp = a(k): a(k) = a(i): a(i) = temp -未给定 9. Next i -未给定 10. End Sub -未给定 问题 4 得 0 分,满分 20 分 编写Sub过程求一元二次方程的实数解,并通过事件过程调用它。 Private Sub Command1_Click() Dim a As Double, b As
17、Double, c As Double, y1 As Double, y2 As Double a = 3: b = 1: c = 5 If root(a, b, c, y1, y2) Then Print y1, y2 Else Print "方程无实数解!" End IfEnd Sub 正确答案所选答案1. Private Function root(ByVal a As Double, ByVal b As Double, ByVal c As Doub
18、le, x1 As Double, x2 As Double) As Boolean -未给定 2. Dim d As Double -未给定 3. d = b * b - 4 * a * c -未给定 4. If d < 0 Then -未给定 5. root = False -未给定 6. Else -未给定 7. root = Truex1 = (-b + Sqr(d) / (2 * a): x2 = (-b - Sqr(d) / (2 * a)-未给定 8. End If -未给定 9. End Function -未给定 问题 5 得 0 分,满分 20
19、 分 编写一个将一维数组倒置存放的子过程,并编写简单事件验证子过程的正确性。 Private Sub Form_Click()Dim b(6) As SingleFor i = 1 To 6 b(i) = InputBox(“b(” + Str(i) + “)=”) Print b(i),Next IPrintCall rev(b(), 6) For i = 1 To 6 Print b(i), Next iEnd Sub 正确答案所选答案1. Public
20、 Sub rev(x() As Double, n As Integer) -未给定 2. Dim i As Integer, t As Double -未给定 3. For i = 1 To n 2 -未给定 4. t = a(i): a(i) = a(n - i + 1): a(n - i + 1) = t -未给定 5. Next i -未给定 6. End Sub -未给定 问题 1 得 0 分,满分 20 分 编写一个将一维数组倒置存放的子过程,并编写简单事件验证子过程的正确性。 Private Sub Form_Click()Dim b(6) As Sing
21、leFor i = 1 To 6 b(i) = InputBox(“b(” + Str(i) + “)=”) Print b(i),Next IPrintCall rev(b(), 6) For i = 1 To 6 Print b(i), Next iEnd Sub 正确答案所选答案1. Public Sub rev(x() As Double, n As Integer) -未给定 2. Dim i As Integer, t As Double -未给定 3. For i =
22、 1 To n 2 -未给定 4. t = a(i): a(i) = a(n - i + 1): a(n - i + 1) = t -未给定 5. Next i -未给定 6. End Sub -未给定 问题 2 得 0 分,满分 20 分 验证哥德巴赫猜想大于6的偶数可以分解为两个素数之和,调用函数过程实现判断任一正整数是不是素数。 Private Function prime(ByVal n As Integer) As Boolean Dim i As Integer prime = True
23、 For i = 2 To Sqr(n)If n Mod i = 0 Then prime = False: Exit For Next iEnd Function 正确答案所选答案1. Private Sub Form_Click() -未给定 2. Dim n1 As Integer, n2 As Integer, n As Integer -未给定 3. Don = InputBox("输入一个大于6 的偶数")-未给定 4. Loop While n <= 6 Or n Mod 2 <>
24、 0 -未给定 5. For n1 = 3 To n / 2 Step 2 -未给定 6. n2 = n - n1 -未给定 7. If prime(n1) And prime(n2) Then -未给定 8. Print n; "=" n1; "+" n2Exit For-未给定 9. End If -未给定 10. Next n1 -未给定 11. End Sub -未给定 问题 3 得 0 分,满分 20 分 编写函数过程,计算某一维数组的最大值,并在窗体的单击事件中,验算其正确性。 Private
25、Sub Form_Click() Dim a(10) As Integer For i = 1 To 10 a(i) = Int(Rnd * 90) + 10 Print a(i); Next i Print Print "最大值是:" fmax(a(), 10)End Sub 正确答案所选答案1. Private Function fmax(x() As Integer, ByVal n As Byte) As Integer -未给
26、定 2. fmax = x(1) -未给定 3. For i = 2 To n -未给定 4. If x(i) > fmax Then fmax = x(i) -未给定 5. Next i -未给定 6. End Function -未给定 问题 4 得 0 分,满分 20 分 从1到10000中找出这样的数,该数各个位的数字的阶乘相加之和等于该数,并将结果输出。要求调用fact函数过程计算阶乘。 Private Function fact(ByVal k As Integer) As Long Dim i As I
27、nteger fact = 1 For i = 2 To k fact = fact * i Next iEnd Function 正确答案所选答案1. Private Sub Form_Click() -未给定 2. Dim k As Integer, a As String, n As Long, i As IntegerDim p As Integer-未给定 3. For k = 1 To 10000 -未给定 4. a = LTrim(Str(k)n = 0-未给定 5. For i = 1
28、To Len(a) -未给定 6. p = Val( Mid(a, i, 1) ) -未给定 7. n = n + fact( p ) -未给定 8. Next i -未给定 9. If n = k Then Print k -未给定 10. Next k -未给定 11. End Sub -未给定 问题 5 得 0 分,满分 20 分 编程,使窗体的背景色在四种颜色间变换。第一次单击窗体是红色;第二次单击窗体是绿色;第三次单击窗体是蓝色;第四次单击窗体是黄色;第五次又重新开始。要求其中使用静态变量。 正确答案所选答案1. Private Su
29、b Form_Click() -未给定 2. Static flag As Integer -未给定 3. flag = flag + 1-未给定 4. Select Case flagCase 1 -未给定 5. BackColor = vbRedCase 2-未给定 6. BackColor = vbGreenCase 3-未给定 7. BackColor = vbBlueCase 4-未给定 8. BackColor = vbYellow -未给定 9. Case 5 -未给定 10. BackColor = vbWhiteflag = 0-未给定 11. End Select -未给定
30、 12. End Sub -未给定 问题 1 得 0 分,满分 20 分 从键盘输入m、n的值(m>0,n>0),求 y = m! + n!, 并在窗体上显示结果。要求用函数实现求阶乘的功能。 正确答案所选答案1. Public Function fact(k As Integer) As Long -未给定 2. Dim i As Integerfact = 1 -未给定 3. For i = 1 To k -未给定 4. fact = fact * i -未给定 5. Next i -未给定 6. End FunctionPrivate Sub Form
31、_Click()-未给定 7. Dim m As Integer, n As Integer -未给定 8. Dom = InputBox("") -未给定 9. n = InputBox("")Loop Until m > 0 And n > 0-未给定 10. Print fact(m) + fact(n) -未给定 11. End Sub -未给定 问题 2 得 0 分,满分 20 分 两质数的差为2,称此两质数为质数对,设计一个程序找出100以内的质数对,并在窗体上成对显示结果。要求质数的判断用自
32、定义函数完成。 正确答案所选答案1. Private Function prime(ByVal k As Integer) As Boolean -未给定 2. Dim i As IntegerIf k < 2 Then -未给定 3. prime = False -未给定 4. Else -未给定 5. For i = 2 To Sqr(k) -未给定 6. If k Mod i = 0 Then Exit For -未给定 7. Next iIf i > Sqr(k) Then prime = True Else prime = False-未给定 8. End I
33、f -未给定 9. End FunctionPrivate Sub Form_Click()-未给定 10. Dim n As Integer -未给定 11. For n = 3 To 100 Step 2 -未给定 12. If prime(n) And prime(n + 2) Then Print n; n + 2 -未给定 13. Next n -未给定 14. End Sub -未给定 问题 3 得 0 分,满分 20 分 输入n后,再输入n个数a1 ,a2 ,.,an ,按照下列公式计算s的值并显示。 编写事件过程Command1_
34、Click(),计算s值,其中 v 值要求调用函数过程 f 来完成。已知求v值的函数过程 f程序如下。Private Function f (x() As Single, n As Integer) as single Dim i As Integer For i = 1 To n f = f + x(i) Next i f = f / nEnd Function 正确答案所选答案1. Private Sub Command1_Click() -未给定 2. Dim a() As Sing
35、le, n As Integer, s As SingleDim v As Single, i As Integer-未给定 3. n = InputBox("请输入n的值")ReDim a(n)-未给定 4. For i = 1 To n -未给定 5. a(i) = InputBox("") -未给定 6. Next iv = f(a, n)-未给定 7. For i = 1 To n -未给定 8. s = s + ( a(i) - v ) 2 -未给定 9. Next i -未给定 10. s = Sqr(s) / n -未给定 11. Prin
36、t s -未给定 12. End Sub -未给定 问题 4 得 0 分,满分 20 分 编制函数过程求二维数组a(n,n)的对角线上各元素的和。 正确答案所选答案1. Public Function ff(a() As Single, n As Integer) As Single -未给定 2. Dim i As Integer, j As Integerff = 0-未给定 3. For i = 1 To nFor j = 1 To n-未给定 4. If i = j Or i + j = n + 1 Then ff = ff + a(i
37、, j) -未给定 5. Next j -未给定 6. Next i -未给定 7. End Function -未给定 问题 5 得 0 分,满分 20 分 编写一子过程,将数组a(n, n)转置。 正确答案所选答案1. Public Sub ff(a() As Single, n As Integer) -未给定 2. Dim i As Integer, j As Integer, t As Single -未给定 3. For i = 2 To nFor j = 1 To i-1-未给定 4. t = a(i, j) -未给定 5. a(
38、i, j) = a(j, i) -未给定 6. a(j, i) = t -未给定 7. Next j -未给定 8. Next i -未给定 9. End Function -未给定 问题 1 得 0 分,满分 20 分 编写Sub过程求一元二次方程的实数解,并通过事件过程调用它。 Private Sub Command1_Click() Dim a As Double, b As Double, c As Double, y1 As Double, y2 As Double a = 3: b = 1: c =
39、 5 If root(a, b, c, y1, y2) Then Print y1, y2 Else Print "方程无实数解!" End IfEnd Sub 正确答案所选答案1. Private Function root(ByVal a As Double, ByVal b As Double, ByVal c As Double, x1 As Double, x2 As Double) As Boolean -未给定 2. Dim d As Double -未给定 3. d
40、= b * b - 4 * a * c -未给定 4. If d < 0 Then -未给定 5. root = False -未给定 6. Else -未给定 7. root = Truex1 = (-b + Sqr(d) / (2 * a): x2 = (-b - Sqr(d) / (2 * a)-未给定 8. End If -未给定 9. End Function -未给定 问题 2 得 0 分,满分 20 分 产生10个30,50的随机整数,并按从小到大的顺序打印出来,要求调用Swap子过程实现两个数交换。 Public Sub S
41、wap(a As Integer, b As Integer) Dim temp As Integer temp = a : a = b : b = tempEnd Sub 正确答案所选答案1. Private Sub form_click() -未给定 2. Dim a(10) As Integer, i As Integer, j As Integer -未给定 3. For i = 1 To 10 -未给定 4. a(i)= Int(Rnd * 21) + 30Next i-未给定 5. For i = 1 To 9
42、 -未给定 6. For j = i + 1 To 10 -未给定 7. If a(i) > a(j) Then -未给定 8. Call Swap(a(i), a(j) -未给定 9. End If -未给定 10. Next j -未给定 11. Form1.Print a(i);Next i-未给定 12. Form1.print a(10)-未给定 13. End Sub -未给定 问题 3 得 0 分,满分 20 分 求下面表达式的值,并在窗体上输出。要求m与n的值在窗体单击事件中用Inputbox()函数输入,且同为正整数,m&
43、gt;n。通过函数过程实现求阶乘的功能。 Private Sub Form_Click() Dim m As Integer, n As Integer Do m = InputBox("m=", "m>0,m必须大于n")n = InputBox("n=", "n>0") Loop While m <= n Or m < 0 Or n < 0 Print f
44、act(m) / fact(n) / fact(m - n)End Sub 正确答案所选答案1. Private Function fact(ByVal k As Integer) As Long -未给定 2. Dim i As Integer -未给定 3. fact = 1 -未给定 4. For i = 2 To k -未给定 5. fact = fact * i -未给定 6. Next i -未给定 7. End Function -未给定 问题 4 得 0 分,满分 20 分 验证哥德巴赫猜想大于6的偶数可以分解为两个素数之和,调用函数过程实
45、现判断任一正整数是不是素数。 Private Function prime(ByVal n As Integer) As Boolean Dim i As Integer prime = True For i = 2 To Sqr(n)If n Mod i = 0 Then prime = False: Exit For Next iEnd Function 正确答案所选答案1. Private Sub Form_Click() -未给定 2. Dim n1 As Integ
46、er, n2 As Integer, n As Integer -未给定 3. Don = InputBox("输入一个大于6 的偶数")-未给定 4. Loop While n <= 6 Or n Mod 2 <> 0 -未给定 5. For n1 = 3 To n / 2 Step 2 -未给定 6. n2 = n - n1 -未给定 7. If prime(n1) And prime(n2) Then -未给定 8. Print n; "=" n1; "+" n2Exit For-未给定 9. End If -
47、未给定 10. Next n1 -未给定 11. End Sub -未给定 问题 5 得 0 分,满分 20 分 编制通用函数过程fsum,计算Single类型一维数组所有元素的和。 正确答案所选答案1. Private Function fsum(a() As Single, n As Integer) As Single -未给定 2. Dim i As Integer -未给定 3. For i = 1 To n -未给定 4. fsum = fsum + a(i) -未给定 5. Next i -未给定 6. End Function
48、-未给定 问题 1 得 0 分,满分 20 分 验证哥德巴赫猜想大于6的偶数可以分解为两个素数之和,调用函数过程实现判断任一正整数是不是素数。 Private Function prime(ByVal n As Integer) As Boolean Dim i As Integer prime = True For i = 2 To Sqr(n)If n Mod i = 0 Then prime = False: Exit For Next iEnd Func
49、tion 正确答案所选答案1. Private Sub Form_Click() -未给定 2. Dim n1 As Integer, n2 As Integer, n As Integer -未给定 3. Don = InputBox("输入一个大于6 的偶数")-未给定 4. Loop While n <= 6 Or n Mod 2 <> 0 -未给定 5. For n1 = 3 To n / 2 Step 2 -未给定 6. n2 = n - n1 -未给定 7. If prime(n1) And prime(n2) Then -未给定 8. Pri
50、nt n; "=" n1; "+" n2Exit For-未给定 9. End If -未给定 10. Next n1 -未给定 11. End Sub -未给定 问题 2 得 0 分,满分 20 分 输入n后,再输入n个数a1 ,a2 ,.,an ,按照下列公式计算s的值并显示。 编写事件过程Command1_Click(),计算s值,其中 v 值要求调用函数过程 f 来完成。已知求v值的函数过程 f程序如下。Private Function f (x() As Single, n As Integer)
51、 as single Dim i As Integer For i = 1 To n f = f + x(i) Next i f = f / nEnd Function 正确答案所选答案1. Private Sub Command1_Click() -未给定 2. Dim a() As Single, n As Integer, s As SingleDim v As Single, i As Integer-未给定 3. n = InputBox("请输入n的值")R
52、eDim a(n)-未给定 4. For i = 1 To n -未给定 5. a(i) = InputBox("") -未给定 6. Next iv = f(a, n)-未给定 7. For i = 1 To n -未给定 8. s = s + ( a(i) - v ) 2 -未给定 9. Next i -未给定 10. s = Sqr(s) / n -未给定 11. Print s -未给定 12. End Sub -未给定 问题 3 得 0 分,满分 20 分 编写子过程DeleStr(s1,s2),将字符串s1中出现的字符串s2删去,结果仍存放在s1中。例如:s1=“1234567ABCDEF456789”, s2=“4567”结果:s1=“123ABCDEF89”正确答案所选答案1. Private Function delestr( s1 As String, s2 As String ) As String -未给定 2. Dim s As String, m%, n%, k%m = Len( s2 )-未给定 3. Do While InStr( s1, s2 ) > 0 -未给定 4. k = Len( s1 )n = I
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论