05年秋江苏计算机二级VB上机试题及答案 下载本文

内容发布更新时间 : 2024/12/27 22:42:16星期一 下面是文章的全部内容请认真阅读。

Text2 = Bin End Sub

Private Sub Trans(Bin As String, K As Integer) Dim S As String, I As Integer, N As Integer Do While K > 0 S = K Mod 2 & S K = K \\ 2 Loop

S = \

Bin = Bin & Right(S, 4) End Sub

[题目4]编写程序,找出由1,2,3,4四个不同数字组成的4位整数中的素数。 [编程要求]

1程序参考界面如图2所示,编程时不得增加或减少界面对象或改变对象的种类,窗体及界面元素大小适中,且均可见;

2单击“开始”按钮,生成(或筛选出)由1,2,3,4四个数字组成的4位整数,并显示在列表框List1中,在列表框List2中显示其中的素数;

3单击“清理”按钮,则将两个列表框清空;单击“退出”按钮,结束程序运行; 4程序中必须包含一个判断某数是否为素数的通用过程。

答: 5

源程序:

Private Sub Command1_Click()

Dim i As Integer, j As Integer, k As Integer, t As Integer, s As String For i = 1 To 4 For j = 1 To 4 For k = 1 To 4 For t = 1 To 4

If i <> j And i <> k And i <> t And j <> k And j <> t And k <> t Then s = i & j & k & t List1.AddItem s

If prime(Int(s)) Then List2.AddItem s End If Next t Next k Next j Next i End Sub

Private Function prime(ByVal x As Integer) As Boolean Dim i As Integer prime = True For i = 2 To Sqr(x)

If x Mod i = 0 Then prime = False: Exit Function Next i End Function

Private Sub Command2_Click() List1.Clear List2.Clear End Sub

Private Sub Command3_Click() End End Sub

[题目5]下面程序的功能是:从由2,4,5,7四个数字组成的没有重复数字的24个四位数中,找出一个具有倍数关系的四位数对。本题程序界面如图1。

答:

源程序: Option Explicit

Private Sub Compare(A() As Integer, S As String, Idx As Integer) Dim I As Integer, J As Integer For I = 1 To Idx For J = 1 To Idx

If A(I) Mod A(J) = 0 And J <> I Then

S = A(I) & \是\的\倍\ Text1 = S Exit Sub End If Next J Next I End Sub

7

Private Sub Command1_Click()

Dim N(100) As Integer, I As Integer, S As String, Idx As Integer Dim J As Integer, Ch As String * 1, K As Integer For I = 2457 To 7542 S = CStr(I) For J = 1 To 4 Ch = Mid(S, J, 1)

If Ch <> \ K = J Do

K = K + 1

If Ch = Mid(S, K, 1) Then Exit For Loop Until K > 4 Next J If J > 4 Then Idx = Idx + 1 N(Idx) = I List1.AddItem I End If Next I

Call Compare(N, S, Idx) End Sub

[题目6]编写程序:生成两个等差数列A={3,10,17,24,31,……,108}与B={3,8,13,18,23,……,108},再找出两个数列中的相同项。 [编程要求]

1. 程序参考界面如图2所示,编程时不得增加或减少界面对象或改变对象的种类,窗体及界面元素大小适中,且均可见;