Write a Ruby program to find the larger between the first and last elements of a given array of integers of length 3

  • برمجة
  • برمجة روبي

 Write a Ruby program to find the larger between the first and last elements of a given array of integers of length 3. Replace all the other values to be that value. Return the changed array.

الأجوبة

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]
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...