VB数组关于交集并集的编程
集合a包含1,5,4,3,26,集合b包含5,7,8,3,42,6.求两集合的交集并集。(用VB)(提示:交集:将a中的每个元素与b的第一个元素比,有相同则取,依此类推)...
集合a包含1,5,4,3,26,集合b包含5,7,8,3,42,6.求两集合的交集并集。(用VB)(提示:交集:将a中的每个元素与b的第一个元素比,有相同则取,依此类推)
展开
1个回答
2013-04-13
展开全部
Private Sub Form_Click()
Dim a(1 To 5) As Integer
Dim b(1 To 6) As Integer
a(1) = 1
a(2) = 5
a(3) = 4
a(4) = 3
a(5) = 26
b(1) = 5
b(2) = 7
b(3) = 8
b(4) = 3
b(5) = 42
b(6) = 6
For i = 1 To 6
For j = 1 To 5
If b(i) = a(j) Then
Print "交集为" & b(i)
End If
Next j
Next i
End Sub
并集是怎么定义的啊,忘了.
Dim a(1 To 5) As Integer
Dim b(1 To 6) As Integer
a(1) = 1
a(2) = 5
a(3) = 4
a(4) = 3
a(5) = 26
b(1) = 5
b(2) = 7
b(3) = 8
b(4) = 3
b(5) = 42
b(6) = 6
For i = 1 To 6
For j = 1 To 5
If b(i) = a(j) Then
Print "交集为" & b(i)
End If
Next j
Next i
End Sub
并集是怎么定义的啊,忘了.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询