Write a Ruby program to compute the sum of the two integers, if the two values are equal return double their sum otherwise return their sum

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

Write a Ruby program to compute the sum of the two integers, if the two values are equal return double their sum otherwise return their sum.

الأجوبة

def sum_double(x, y)
    x == y ? (x+y)*2 : x+y
end

print sum_double(5, 5),"\n" 
print sum_double(4, 5)
Output:
20
9
هل كان المحتوى مفيد؟

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

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