array[10]={2,3424,4234,42,234,234,23423,123,342,3}
In this array, how do I find the first five biggest numbers and the position of those numbers? I.e I want the output as
biggest number was 23423 and its position was 7
Like this ^^^ for the five biggest numbers and their positions.
I want code for this; I am a student.
Is the array guaranteed to have 10 elements? Are they guaranteed to be positive? If so, you can multiply each element by 10 and add the index to it, then sort the array, then take the 5 largest elements; divide by 10 (integer division) to get the original number, and take % 10 to get the original position.
For a more general solution, you could create a struct to hold the value and original index, then sort the array of structs based on value.
Use any basic sorting algorithm.