Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

find kth max and min element in an array

#include <bits/stdc++.h> 
using namespace std;

int main(){
  	const int size = 10;
  	int k = 3; //Can be any number smalled than size
	int array[size] = {5,2,8,34,73,82,1,6,19,29};
	sort(array,array+size);
	int smallestKthElement = array[k-1];	
	int largestKthElement = array[size-k];
}
 
PREVIOUS NEXT
Tagged: #find #kth #max #min #element #array
ADD COMMENT
Topic
Name
5+8 =