Write a Ruby program to check two integer values and return true if they are both in the range 10..20 inclusive,

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

Write a Ruby program to check two integer values and return true if they are both in the range 10..20 inclusive, or they are both in the range 20..30 inclusive.

الأجوبة

def test_int(a, b)
   return  (((a >= 10 && a <= 20) && (b >= 10 && b <= 20)) ||
	((a >= 20 && a <= 30) && (b >= 20 && b <= 30)));
end

print test_int(10, 15),"\n"
print test_int(6, 9),"\n"
print test_int(22, 30),"\n"
print test_int(45, 55)
Output:
true
false
true
false
هل كان المحتوى مفيد؟

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

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