human
Mean of given array after removal of K percent of smallest and largest array elements | Function to calculate the mean of a given array after removal of Kth percent of smallest and largest array elements.
Sort the array.
Find the K - th percent of the array size.
Traverse the array.
Skip the first K - th percent & last K - th percent array elements.
Mean of the rest of elements.
Print mean upto 5 decimal places.
Driver Code"
Solution in Python:
assistant
#Here is code to mean of given array after removal of K percent of smallest and largest array elements and the other steps required.
 def meanOfRemainingElements ( arr , N , K ) :
	arr . sort ( )
	kthPercent = ( N * K ) / 100
	sum = 0
	for i in range ( N ) :
		if ( i >= kthPercent and i < ( N - kthPercent ) ) :
			sum += arr [ i ]
	mean = sum / ( N - 2 * kthPercent )
	print ( ' % .5f ' % mean )
arr = [ 6 , 2 , 7 , 5 , 1 , 2 , 0 , 3 , 10 , 2 , 5 , 0 , 5 , 5 , 0 , 8 , 7 , 6 , 8 , 0 ]
arr_size = len ( arr )
K = 5
meanOfRemainingElements ( arr , arr_size , K )