Write a function called kthGreatest that accepts an integer array a, the size of array N and an integer k as its parameters and returns the kth greatest element.(PLEASE DO NOT UPDATE THE OUTSIDE OF THE COMMENTS)
Main function is already implemented for you, DO NOT CHANGE ANYTHING IN IT. You will just implement the function definition above the main function.
Assumptions:
N will be larger than or equal to k and k will not be equal to 0.
N will not be greater than 50.
Hint:
You may want to sort the array first.
Examples:
5 2
2 8 4 5 3
|
5 |
8 1
74 85 20 100 99 86 53 4
|
100 |
2 2
3 5
|
3 |
Important issues about all exams/projects/quizzes:
- Update just Question.c file, not Question.txt.
- Make changes only between the following comments(DO NOT modify these comments or anything outside the region marked by the comments):
- // == CHANGE STARTS BELOW THIS LINE ==
- // == CHANGE STOPS ABOVE THIS LINE ==
- If you modify these comments for any reason, you can copy/paste the initial version from Question.txt into Question.c. Note that Question.txt is not graded at all, so anything you write in Question.txt will be discarded.
- To avoid getting the 'Binary Not Found' error, SAVE and BUILD your code before RUN.
- Do not add any extra messages message for input/output such as 'Enter an integer:', 'The result is:', etc. Any additional text that appears in the output will cause you to get no points from the question.
- Input and output of your program must be just like those in the Examples table above.