大学vb考试题库(1) 下载本文

内容发布更新时间 : 2024/11/17 2:25:59星期一 下面是文章的全部内容请认真阅读。

Next i

Picture1.Print avera End Sub

Function ss(n) As Integer Dim i%, tag As Boolean tag = True

For i = 3 To n / 2

If (n Mod i) = 0 Then tag = False Next i

If tag Then ss = n End Function

40.编一子过程Procmin(a(),amin),求一维数组中a的最小值amin.

(随机产生10个200-400之间的数,并显示数组各元素;调用子函数,显示最小值) Private Sub Form_Click() Dim a(1 To 10), amin, i% For i = 1 To 10

a(i) = Int(Rnd * 200 + 200) Print a(i); Next i

Call s(a(), amin) Print

Print \ End Sub

Sub s(b(), min) Dim i%

min = b(LBound(b))

For i = LBound(b) + 1 To UBound(b) If b(i) < min Then min = b(i) Next i End Sub

41:.编一冒泡程序,对已知整数按递减次序排列,用子过程 Sub sort(a())

Dim imin%, i%, j%

For i = 0 To UBound(a) - 1 For j = 0 To UBound(a) - 1 - i If a(j+1) > a(j ) Then

t = a(j): a(j) = a(j + 1): a(j + 1) = t End If Next j Next i End Sub

Private Sub Form_Click() Dim b(), i%

b = Array(8, 9, 4, 2, 6)

Call sort(b())

For i = 0 To UBound(b) Print b(i); Next i End Sub

43.用选择排序法子过程对已知的若干整数按递增次序排列 Sub sort(a())

Dim imin%, i%, j%

For i = 0 To UBound(a) - 1 imin = i

For j = i + 1 To UBound(a) If a(j) < a(imin) Then imin = j Next j

t = a(i): a(i) = a(imin): a(imin) = t Next i End Sub

Private Sub Form_Click() Dim b(), i%

b = Array(8, 9, 4, 2, 6) Call sort(b())

For i = 0 To UBound(b) Print b(i); Next i End Sub

45.编一冒泡程序,对已知整数按递增次序排列,用子过程 Sub sort(a())

Dim imin%, i%, j%

For i = 0 To UBound(a) - 1 For j = 0 To UBound(a) - 1 - i If a(j) > a(j + 1) Then

t = a(j): a(j) = a(j + 1): a(j + 1) = t End If Next j Next i End Sub

Private Sub Form_Click() Dim b(), i%

b = Array(8, 9, 4, 2, 6) Call sort(b())

For i = 0 To UBound(b) Print b(i); Next i End Sub