In: Computer Science
Python code
Screenshot
Program
import numpy as np
def tallestHeight(heights):
#Set first element as maximum height
max=heights.flat[0]
#Traverse each element of the array and set max
height
for i in np.nditer(heights):
if i > max:
max = i
#Return max height
return max
#Test
N=22 # for 22 players
H= np.random.uniform(5.5, 8.0, size=(1,N))
print("random float array in [5.5, 8.0] \n", H,"\n")
print("Tallest player height = %.8f"%tallestHeight(H))
Output
random float array in [5.5, 8.0]
[[7.53450756 7.14316657 6.34246178 7.78411501 5.51282309
7.74859553
7.62140945 5.59460712 5.86448351 5.87944372 5.76947077
6.00740081
7.39301746 7.57616436 7.61333592 7.01673579 5.80868431
6.32778803
6.98718796 7.79752271 7.42343135 5.51697551]]
Tallest player height = 7.79752271
-------------------------------------------------------------------------------------------------------------------
Matlab
Screenshot
Program
function max=tallestHeight(H)
max=H(1);
for i=H
if i>max
max=i;
end
end
end
Test:-
H= (8.0-5.5).*rand(1, 22, 'double')+5.5
fprintf("Tallest player height = %.8f",tallestHeight(H));