Write a Ruby program to check three given integers and return their sum

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

Write a Ruby program to check three given integers and return their sum. However, If one of the values is the same as another of the values, it does not count towards the sum.

الأجوبة

def check_num(a, b, c)
    if a==b && b==c
        return 0
    elsif a==b
        return c
    elsif a==c
        return b
    elsif b==c
        return a
    else
        return a+b+c
    end
end
print check_num(5, 5, 5),"\n"
print check_num(5, 5, 7),"\n"
print check_num(5, 7, 5),"\n"
print check_num(7, 5, 5),"\n"
print check_num(1, 2, 3),"\n"

Output:

0
7
7
7
6
هل كان المحتوى مفيد؟

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

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