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.
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer