Answer to Question #252647 in C++ for koi

Question #252647

Develop an algorithm in form of a pseudocode to solve the following problem: You are given an array of positive numbers, determine if there are any two integers in the array whose sum is equal to the given value X, and display all pairs of integers in the array that add up to X. Look at the below test case to guide you. (NB: do not write a C++ program but pseudocode) [5 Marks] Array: {7,1,2,8,4,3} Target sum/value (X)= 10 Expected Output: 7 + 3 = 10, 2 + 8 = 10


1
Expert's answer
2021-10-17T09:29:29-0400
// arr - array of integers
// X - target sum
Set S = empty // set of pairs with sum equal X
for i in {0, length(arr)}
  for j in {i + 1, length(arr)}
    if arr[i] + arr[j] == X and { arr[i], arr[j] } not in S
      // add pair to set
      S += { arr[i], arr[j] }
for {x,y} in S
  print "${x} + ${y} = ${X}\m"
   




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