526,251 views
44 votes
44 votes
write a function that takes two integer arrays as input return true if any two of the numbers in the first array input add up to any of the numbers in the second array tests return false

User Shawn Tabrizi
by
2.7k points

1 Answer

9 votes
9 votes

Answer:

Step-by-step explanation:

This program is written in Python. It is a function that takes in two arrays. Then it loops through the first array twice, adding each element with the others and comparing the sum to the values in the second array. If a similar value is found in the second array, the program prints out the value and returns True to the user. Otherwise, it returns False. A test case has been created with two array variables that print out False, the output can be seen in the attached image below.

def sumArray(arr1, arr2):

for i in range(len(arr1)):

for x in range(len(arr1)):

sum = 0

if i != x:

sum = arr1[i] + arr1[x]

if sum in arr2:

print(str(sum) + "Found in Second Array")

return True

return False

arr1 = [1, 9, 10, 44]

arr2 = [2, 4, 8, 14]

print(sumArray(arr1, arr2))

write a function that takes two integer arrays as input return true if any two of-example-1
User Aaronb
by
3.3k points