Answer to Question #278742 in Algorithms for Moon

Question #278742

The challenge is to find all the pairs of two integers in an unsorted array that sum up to a given S.




For example, if the array is [3, 5, 2, -4, 8, 11] and the sum is 7, your program should return [[11, -4], [2, 5]] because 11 + -4 = 7 and 2 + 5 = 7.


1
Expert's answer
2021-12-13T04:28:19-0500
Start 
  Declare array array
  Declare array array2d
  Declare variable s
  Read array from the keyboard
  Read s
  for i = 0 to array length do
    for j = 1 to array length-1 do
      sum=array[i]+array[j]
      if sum=s then
        Set array2d = [array[i],array[j]]
      end if
    end for
  end for
  Display array2d
Stop

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS