vb程序阅读题与填空题

发布时间 : 星期日 文章vb程序阅读题与填空题更新完毕开始阅读

Option Explicit Sub First() Static s As Integer Dim i As Integer For i = 1 To 10 Step 2 s = s + i Next i Print s; End Sub

Private Sub Command1_Click()

Dim a As Integer, b As Integer, c As Integer Call First End Sub

10.运行下列程序,在立即窗口上第二行显示________;第三行显示________。 Option Explicit Dim a As Integer

Private Sub Command1_Click() Dim b As Integer Dim d As Integer a = 1: b = 2 d = fun(a, fun(a, b)) Debug.Print a, b, d End Sub

1.写出下列程序的运行结果。 Private Sub Command1_Click() Dim x%, y% x = 18 y = 28 Call swap(x, y) Print x, y End Sub Private Function fun(k As Integer, n As Integer) Private Sub swap(a%, b%) As Integer Dim t% Debug.Print k, n; k = n + a + k n = k + a + n fun = k + n Debug.Print fun End Function

17

t = a a = b b = t End Sub

三、程序阅读题:

3.写出下列程序的执行结果。 Option Explicit

Sub Ss(ByVal x As Integer, ByRef y As Integer, z As Integer) x = x + 1 y = y + 1 z = z + 1 End Sub

Private Sub Command1_Click()

Dim a As Integer, b As Integer, c As Integer a = 1: b = 2: c = 3 Call Ss(a, b, c) Print a, b, c End Sub

4.在窗体上画一个命令按钮,名称为Command1,程序运行后,写出下面程序的输出结果。

Function M(x As Integer,y As Integer) As Integer M=IIf(x>y,x,y) End Function

Private Sub Command1_Click() Dim a As Integer,b As Integer a=100 b=200 print M(a,b) End Sub

5.写出下面程序的输出结果。 Private Sub Command1_Click() Dim k As Integer For i=3 To 5 Step 2 k=i Call text(k) m=m+k Next i Print m;i End Sub

Private Sub test(n As Integer) n=1+2*n

18

7.写出下面程序的输出结果。 Private Function f() As Integer Static i As Integer Dim s As Integer i=i+1 s=s+i f=s End Function Private Sub Command1_Click() Dim i As Integer Dim a As Integer For i=1 To 4 a=a+f() Next i Print a End Sub End Sub

6.写出下面程序的输出结果。 Function F(a As Integer) b=0 Static c b=b+1 c=c+1 F=a+b+c End Function

Private Sub Command1_Click() Dim a As Integer a=2 For i=1 To 3 Print F(a) Next i End Sub End Sub

9.当发生了Command1_Click事件后, 写出下面程序的输出结果。

8.写出下面程序的输出结果。 Public Function myfun(m!,n%) As Integer If n=0 Then myfun=1 Else If n Mod 2=1 Then myfun=m*myfun(m,n\\2) Else myfun=myfun(m,n\\2)\\m Public Function age(n As Integer) As Integer End If Dim k As Integer End If If n=1 Then k=1 Else

k=2*age(n-1)+3 End If age=k End Function

Private Sub Command1_Click() Dim a As Integer,k As Integer k=5 : a=age(5) : Print a End Sub

四、程序填空题:

3.以下Function过程Odd用于判断一个数是否为奇数。当单击命令按钮时,随机产生一个二位数,设用Odd过程判断该数是否是奇数。如果是奇数,则显示True,否则显示False。 Option Explicit

Private Sub Command1_Click()

19

End Function Private Sub Command1_Click() Print myfun(3,11) Dim x As Integer

x = 【1 】 Print x, Odd(x) End Sub

Function Odd(ByVal n As Integer) As Boolean If 【2 】 Then Odd = False Else Odd = True End If End Function

4.下列程序的功能是求两个正整数的最大公约数。阅读下列程序,请在空格处天如相应的语句,使之完成上述功能。 Option Explicit

Private Sub Command1_Click()

Dim a As Integer, b As Integer, g As Integer a = InputBox(\输入数字a:\b = InputBox(\输入数字b:\

【1 】 = Gc(a, b) Print a; \和\的最大公约数是:\End Sub

Private Function Gc(ByVal x As Integer, 【2 】As Integer) Dim z As Integer z = x Mod y Do While z <> 0 x = y y = z z = x Mod y Loop

Gc = 【3 】 End Function

5.下列程序的功能是将一个数的各位数字相乘并打印在窗体上。阅读下列程序,请在空格处天如相应的语句,使之完成上述功能。 Option Explicit

Private Sub Command1_Click() Dim n As Long

n = InputBox(\请输入一个数\Print Fun1(n)

20

联系合同范文客服:xxxxx#qq.com(#替换为@)