交
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
For i = 1 To 10
If a(i) <> b(i) Then
c(i)=a(i)
End If
Next i
和
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
For i = 1 To 10
If a(i) <> b(i) Then
c(i)=a(i)+b(i)
End If
Next i
差
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
For i = 1 To 10
If a(i) <> b(i) Then
c(i)=a(i)-b(i)
End If
Next i
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
For i = 1 To 10
If a(i) <> b(i) Then
c(i)=a(i)
End If
Next i
和
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
For i = 1 To 10
If a(i) <> b(i) Then
c(i)=a(i)+b(i)
End If
Next i
差
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
For i = 1 To 10
If a(i) <> b(i) Then
c(i)=a(i)-b(i)
End If
Next i
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
For i = 1 To 10
If a(i) <> b(i) Then
c(i)=a(i)
End If
Next i
和
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
For i = 1 To 10
If a(i) <> b(i) Then
c(i)=a(i)+b(i)
End If
Next i
差
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
For i = 1 To 10
If a(i) <> b(i) Then
c(i)=a(i)-b(i)
End If
Next i
Dim i As Integer, j As Integer, k As Integer, c(1 To 20) As String
dim Count as integer
count=0
For i = 1 To 10
for j=1 to 10
If a(i) = b(j) Then
c(count)=a(i)
count=count+1
exit for
End If
next j
Next i和
Dim i As Integer, j As Integer, k As Integer, c(1 To 20) As String
dim Count as integer,Add as integer
for i=1 to 10
c(i)=a(i)
next
count=10
For i = 1 To 10
Add=0
for j=1 to 10
If a(i) = b(j) Then Add=1
Next i
if Add=0 then
count=count+1
c(count)=a(i)
end if
next j
结果在数据C里
差的话要复杂一些了
补一下差的运算
Dim i As Integer, j As Integer, k As Integer, c(1 To 10) As String
dim Count as integer,Add as integercount = 0
For i = 1 To 10
Add=0
for j=1 to 10
If a(i) = b(j) Then
Add=1
exit for
end if
Next j
if Add=0 then
count=count+1
c(count)=a(i)
end if
next i上面C中的数据为A-B的,这要事先保证A、B同一个空间,并且A要大于B
交和差运算已经实现了,不过redwrite(红妆素裹) 提供的和运算好像有点问题?
不单循环变量位置不对,c(count)=a(i)这句应该改为c(count)=b(j)吧?
Dim i As Integer, j As Integer, k As Integer, c(1 To 20) As String
Dim Count As Integer, Add As Integer
For i = 1 To 10
c(i) = a(i)
Next
Count = 10
For i = 1 To 10
Add = 0
For j = 1 To 10
If a(i) = b(j) Then Add = 1
Exit For
Next j
If Add = 0 Then
Count = Count + 1
c(Count) = b(j)
End If
Dim i As Integer, j As Integer, k As Integer, c(1 To 20) As String
Dim Count As Integer, Add As Integer,my
For i = 1 To 10
c(i) = a(i)
Next
Count = 10
For i = 1 To 10
Add = 0
For j = 1 To 10
If b(i)=a(j) Then Add = 1
Exit For
Next j
If Add = 0 Then
Count = Count + 1
c(Count) = b(i)
End If
next i这个方法前提是两个数组自身的数据是不相同的。
奇怪的是按照这个算法得到的输出应该是a与b的和集。但是调试中输出的结果却是简单的把a与b数组相加,两数组中重复的元素也照样重复输出了?
到底是怎么回事呢?
Dim a(1 To 10) As Integer, b(1 To 10) As Integer, c(1 To 20) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 10
a(i) = i
b(i) = 5 + i
Next
Dim Count As Integer, Add As Integer
For i = 1 To 10
c(i) = a(i)
Next
Count = 10
For i = 1 To 10
Add = 0
For j = 1 To 10
If b(i) = a(j) Then
Add = 1
Exit For
End If
Next j
If Add = 0 Then
Count = Count + 1
c(Count) = b(i)
End If
Next i
For i = 1 To 20
Text1.Text = Text1.Text + " " + Trim(Str(c(i)))
Next
End Sub这次可以了,这个方法前提是两个数组自身的数据是不相同的。
Dim a(1 To 10) As Integer, b(1 To 10) As Integer, c(1 To 20) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 10
a(i) = i
b(i) = 5 + i
Next
Dim Count As Integer, Add As Integer
For i = 1 To 10
c(i) = a(i)
Next
Count = 10
For i = 1 To 10
Add = 0
For j = 1 To 10
If b(i) = a(j) Then
Add = 1
Exit For
End If
Next j
If Add = 0 Then
Count = Count + 1
c(Count) = b(i)
End If
Next i
For i = 1 To 20
Text1.Text = Text1.Text + " " + Trim(Str(c(i)))
Next
End Sub
that's all right