2015-2016第一学期vb试卷A 下载本文

2015~2016学年第一学期VB期末考试(A卷) 2015级

a = a + a fy = a End Function

10.执行下面程序,单击按钮Cmd1后,在InputBox函数对话框中输入4(或直接单击“确

定”按钮),窗体第三行显示的内容是 (12) 。 Option Explicit

Private Sub Cmd1_Click() Dim days As Integer

days = InputBox(\输入正整数\ Print fun(days) End Sub

Private Function fun(D As Integer) As Integer If D = 1 Then fun = 1 Else

fun = 2 * fun(D - 1) + 1 Print D; fun End If End Function

11.以下程序的功能是从随机产生的20 个20~200(含20 和200)的整数中,找出能够同时被3和5 整除的数的最大值,并显示出来。请完善程序。 Option Base 1 Private Sub Command1_Click() Dim a(20) As Integer m = 0 For i = 1 To 20 a(i) = Int(Rnd * (13) ) + 20 If a(i) Mod 3 = 0 and a(i) Mod 5 = 0 Then If a(i) > m Then m = a(i) End If Next i If (14) Then Print \没有满足条件的数\ Else Print \满足条件的数是\ End If End Sub 12、以下程序的功能是:先将随机产生的10 个不同的整数放入数组a 中,再将这10 个数按升序方式输出。请完善程序。 Private Sub Form_Click()

Dim a(10) As Integer, i As Integer Randomize i = 0 Do

第 9 页 共 11 页

2015~2016学年第一学期VB期末考试(A卷) 2015级

num = Int(Rnd * 90) + 10

For j = 1 To I '检查新产生的随机数是否与以前的相同,相同的无效 If num = a(j) Then Exit For Next j

If j > i Then i = i + 1

a(i) = (15) End If

Loop While i < 10 For i = 1 To 9

For j = (16) To 10 If a(i) > a(j) Then temp = a(i) a(i) = a(j) (17) End If Next j Next i

For i = 1 To 10 Print a(i) Next i End Sub

13、以下程序的功能是:找出指定范围内包含因子个数最多的整数,允许因子个数最多的整数不止一个,若有多个则全部输出到文本框中。请完善程序。

Option Explicit Option Base 1

Private Sub Command1_Click()

Dim i As Integer, j As Integer, m As Integer, n As Integer Dim s As String, mx As Integer Dim yz() As Integer, c() As Integer m = Text1: n = Text2 ReDim c(m To n)

第 10 页 共 11 页

2015~2016学年第一学期VB期末考试(A卷) 2015级

For i = (18) s = i & \ Call qyz(i, yz) c(i) = UBound(yz)

For j = 1 To UBound(yz) s = s & yz(j) & \ Next j

s = Left(s, Len(s) - 1) List1.AddItem s Next i mx = c(m)

For i = m+1 To n

If c(i) > mx Then mx = c(i) Next i

For i = m To n

If c(i) = mx Then Text3 = Text3 & i & \ Next i

Text3 = Left(Text3, Len(Text3) - 1) End Sub

Private Sub qyz(ByVal n As Integer, yz() As Integer) Dim i As Integer, p As Integer For i = 1 To n - 1

If (19) Then p = p + 1

(20) yz(p) = i End If Next i End Sub

三、 编程题(10分×1=10分)

题目见答题纸。

第 11 页 共 11 页' 统计因子个数的过程