ProAnswers.org

Find the sum of first n largest numbers in an array

how to Find the sum of first n largest numbers in an array.

1: sum =0; int Array[n];
2: Find the largest number in the array. Add it to sum.
3: Note down the largest number in Array[].
4.Largest number = 0 in the given array.
5. Repeat (from step 2) for n times.

If there were negative number in array, then I THINK it’s better to sort the array and find the sum of n largest number.

Or, in step of finding the largest number, we can keep the condition largest number != 0;