Q:

Write a Ruby program to find the largest value from a given array of integers of odd length. The array length will be a least 1

0

 Write a Ruby program to find the largest value from a given array of integers of odd length. The array length will be a least 1.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def check_array(nums)
    max = nums[0];
	if(max <= nums[nums.length-1])
		max = nums[nums.length-1]
	end
	if(max <= nums[nums.length/2])
		max = nums[nums.length/2]
	end
	return max;
end

print check_array([1, 3, 4]),"\n"
print check_array([1, 2, 7]),"\n"
print check_array([1, 2])  

Output:

4
7
2

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now