vb编写程序实现两个有序数组的输入,显示,并将这两个数组合并为一个新的有序数组,显示新数组。要求:
答案:1 悬赏:60 手机版
解决时间 2021-11-07 09:41
- 提问者网友:疯子也有疯子的情调
- 2021-11-07 04:50
vb编写程序实现两个有序数组的输入,显示,并将这两个数组合并为一个新的有序数组,显示新数组。要求:
最佳答案
- 五星知识达人网友:不想翻身的咸鱼
- 2021-11-07 05:13
Dim a(20) As Integer, b(20) As Integer, c(40) As Integer
Dim n1 As Integer, n2 As Integer, n3 As Integer
Private Sub Command1_Click()
getdata a(), n1
Text1 = Text1 & "A数组:" & vbCrLf
xs a(), n1
End Sub
Private Sub Command2_Click()
getdata b(), n2
Text1 = Text1 & "B数组:" & vbCrLf
xs b(), n2
End Sub
Private Sub Command3_Click()
hebin a(), n1, b(), n2, c(), n3
Text1 = Text1 & "合并以后的C数组:" & vbCrLf
xs c, n3
End Sub
Sub getdata(ByRef a() As Integer, ByRef n As Integer)
While a(n) >= 0
n = n + 1
a(n) = InputBox("请输入升序的整数,以负数结束:")
Wend
n = n - 1
End Sub
Sub xs(ByRef a() As Integer, ByRef n As Integer)
For i = 1 To n
Text1 = Text1 & a(i) & " "
Next i
Text1 = Text1 & vbCrLf & vbCrLf
End Sub
Sub hebin(ByRef a() As Integer, n1 As Integer, ByRef b() As Integer, n2 As Integer, ByRef c() As Integer, ByRef n3 As Integer)
i = 1: j = 1: n3 = 1
While i <= n1 And j <= n2
If a(i) < b(j) Then
c(n3) = a(i)
i = i + 1
Else
c(n3) = b(j)
j = j + 1
End If
n3 = n3 + 1
Wend
While i <= n1
c(n3) = a(i)
i = i + 1
n3 = n3 + 1
Wend
While j <= n2
c(n3) = b(j)
j = j + 1
n3 = n3 + 1
Wend
n3 = n3 - 1
End Sub
Private Sub Form_Load()
Text1 = ""
Text2 = ""
End Sub
追问能具体把整个界面截图给我看吗,我试了一下老是类型不匹配。。。
Dim n1 As Integer, n2 As Integer, n3 As Integer
Private Sub Command1_Click()
getdata a(), n1
Text1 = Text1 & "A数组:" & vbCrLf
xs a(), n1
End Sub
Private Sub Command2_Click()
getdata b(), n2
Text1 = Text1 & "B数组:" & vbCrLf
xs b(), n2
End Sub
Private Sub Command3_Click()
hebin a(), n1, b(), n2, c(), n3
Text1 = Text1 & "合并以后的C数组:" & vbCrLf
xs c, n3
End Sub
Sub getdata(ByRef a() As Integer, ByRef n As Integer)
While a(n) >= 0
n = n + 1
a(n) = InputBox("请输入升序的整数,以负数结束:")
Wend
n = n - 1
End Sub
Sub xs(ByRef a() As Integer, ByRef n As Integer)
For i = 1 To n
Text1 = Text1 & a(i) & " "
Next i
Text1 = Text1 & vbCrLf & vbCrLf
End Sub
Sub hebin(ByRef a() As Integer, n1 As Integer, ByRef b() As Integer, n2 As Integer, ByRef c() As Integer, ByRef n3 As Integer)
i = 1: j = 1: n3 = 1
While i <= n1 And j <= n2
If a(i) < b(j) Then
c(n3) = a(i)
i = i + 1
Else
c(n3) = b(j)
j = j + 1
End If
n3 = n3 + 1
Wend
While i <= n1
c(n3) = a(i)
i = i + 1
n3 = n3 + 1
Wend
While j <= n2
c(n3) = b(j)
j = j + 1
n3 = n3 + 1
Wend
n3 = n3 - 1
End Sub
Private Sub Form_Load()
Text1 = ""
Text2 = ""
End Sub
追问能具体把整个界面截图给我看吗,我试了一下老是类型不匹配。。。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯