第1个回答 2010-07-15
注释步骤嘛,因为太累了,所以简写,估计能看个差不多
在窗体上放一个名为 text1 的TextBox控件,属性改为多行和带滚动条,再放一个按钮,按钮的响应程序如下:
Private Sub Command1_Click()
Const n = 30
Const m = 20
Dim a(n) As Integer, b(m) As Integer, c(m + n) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To n
a(i) = 3 * i
Next i
For j = 1 To m
b(j) = 4 * j
Next j
i = n
j = m
p = 0 ' a数组取净标志
q = 0 ' b
For k = 1 To m + n
If a(i) >= b(j) And p = 0 Then ' a大取a
c(k) = a(i)
If i > 0 Then
i = i - 1
Else
p = 1
End If
ElseIf b(j) > a(i) And q = 0 Then ' b大取b
c(k) = b(j)
If j > 0 Then
j = j - 1
Else
q = 1
End If
End If
If p = 1 Then ' a用完取b
c(k) = b(j)
j = j - 1
End If
If q = 1 Then ' b用完取a
c(k) = a(i)
i = i - 1
End If
Next k
' 输出至 text1
Dim ts As String
For i = 1 To m + n
ts = ts + "i=" + Str(i) + ", c(i) = " + Str(c(i)) + Chr(13) + Chr(10)
Next i
Text1.Text = ts
End Sub
运行结果如下:
i= 1, c(i) = 90
i= 2, c(i) = 87
i= 3, c(i) = 84
i= 4, c(i) = 81
i= 5, c(i) = 80
i= 6, c(i) = 78
i= 7, c(i) = 76
i= 8, c(i) = 75
i= 9, c(i) = 72
i= 10, c(i) = 72
i= 11, c(i) = 69
i= 12, c(i) = 68
i= 13, c(i) = 66
i= 14, c(i) = 64
i= 15, c(i) = 63
i= 16, c(i) = 60
i= 17, c(i) = 60
i= 18, c(i) = 57
i= 19, c(i) = 56
i= 20, c(i) = 54
i= 21, c(i) = 52
i= 22, c(i) = 51
i= 23, c(i) = 48
i= 24, c(i) = 48
i= 25, c(i) = 45
i= 26, c(i) = 44
i= 27, c(i) = 42
i= 28, c(i) = 40
i= 29, c(i) = 39
i= 30, c(i) = 36
i= 31, c(i) = 36
i= 32, c(i) = 33
i= 33, c(i) = 32
i= 34, c(i) = 30
i= 35, c(i) = 28
i= 36, c(i) = 27
i= 37, c(i) = 24
i= 38, c(i) = 24
i= 39, c(i) = 21
i= 40, c(i) = 20
i= 41, c(i) = 18
i= 42, c(i) = 16
i= 43, c(i) = 15
i= 44, c(i) = 12
i= 45, c(i) = 12
i= 46, c(i) = 9
i= 47, c(i) = 8
i= 48, c(i) = 6
i= 49, c(i) = 4
i= 50, c(i) = 3
第2个回答 2010-07-15
Private Sub Command1_Click()
Dim A() As Integer, N As Integer
Dim B() As Integer, M As Integer
Dim C() As Integer, NC As Integer
Dim I As Integer, J As Integer, TM As Integer
'……前面的关于A B数组什么来头我不写了 你知道的
'定义数组C大小
NC = M + N
rdim C(NC)
'把数组A装入C
For I = 1 To N
C(I) = A(I)
Next I
'把数组B装入C
For I = 1 To M
C(N + I) = B(I)
Next I
'对C进行从大到小排序
For I = 1 To NC - 1
For J = I + 1 To NC
If C(I) < C(J) Then
TM = C(I)
C(I) = C(J)
C(J) = TM
End If
Next J
Next I
End Sub本回答被提问者采纳
第3个回答 2010-07-15
Option Explicit
Dim a(4), b(7), c(12)
Private Sub Command1_Click()
Dim i%, j%, k%, m%, n%
i = LBound(a): j = LBound(b): k = LBound(c)
m = UBound(a): n = UBound(b)
While i <= m And j <= n
If a(i) > b(j) Then
c(k) = a(i): i = i + 1: k = k + 1
Else
c(k) = b(j): j = j + 1: k = k + 1
End If
Wend
While k <= m + n - i - j + 1
If i > m Then
c(k) = b(j): j = j + 1: k = k + 1
Else
c(k) = a(i): i = i + 1: k = k + 1
End If
Wend
End Sub