0
if you have to select any two numbers(from 1,2,3,7,8,9) and add them to get 10.what will be the code?
2 Answers
+ 3
Assuming <n> is the highest index in the array, and base index is zero. You can get 10 by adding either one of these :
element[0] + element[n-0]
element[1] + element[n-1]
element[2] + element[n-2]
You can use for loop also, any of the above will give you 10.
Cmiiw, Hth,
+ 8
Select one number from the array.
For each element in the array except for itself, add to the selected element and evaluate if resultant value is equals to 10. If the value is not 10, continue. If the value is 10, break. Repeat this algorithm for the next selected element in the array.