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?

30th Jul 2017, 5:30 AM
Abhishek mohata
Abhishek mohata - avatar
2 odpowiedzi
+ 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,
30th Jul 2017, 7:30 AM
Ipang
+ 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.
30th Jul 2017, 6:26 AM
Hatsy Rei
Hatsy Rei - avatar