Write a Ruby program to find the larger between the first and last elements of a given array of integers of length 3
- برمجة
- برمجة روبي
- 2021-08-31
- mhanasmh00489829403
الأجوبة
def check_array(nums)
maxVal = []
maxVal[0] = nums[0]
if(nums[2] >= maxVal[0])
maxVal[0] = nums[2]
maxVal[1] = maxVal[0]
maxVal[2] = maxVal[0]
end
return maxVal
end
print check_array([1, 2, 5]),"\n"
print check_array([1, 2, 3]),"\n"
print check_array([1, 2, 4])
Output:
[5, 5, 5] [3, 3, 3] [4, 4, 4]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
