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
- Define Target Sum = X
- Get the integer number array as Num
- Get the size of Num array as: L = sizeof(Num)/sizeof(Num[0])
- for (r = 0; r < L ; r++)
{
for (c = 0; c < L; c++)
{
if Num[r] + Num[c] == X
then, Display (Num[r] and Num[c]
}
}
Comments
Leave a comment