I think this should work and be much more efficient than finding each number:
-Totaling all numbers
-Set two to 0
-Write a new amount
-See all the difference factors
-Specify which set of factors is possible, based on the numbers still in the array, since there are no repetitions.
For instance:
Array = {8,6,3,5,4,2,7,7}; // The array is filled with numbers from 1 to 8 just for simplicity.
Array [0] = 0;
Array [1] = 0;
Original amount = 36
New Amount = 28
Difference = 8
Pairs that add up to 8: 7/1, 6/2, 5/3, 4/4
Check 6/2, see that 6 and 2 are still there, exclude this pair. Continue until you find a pair in which no number is in the array. This is your answer. In this case, neither 7 nor 1 is still in the array, so these are two numbers that were missing.
source share