Ruby Basic Exercises: Check three given integers and return true if the three values are evenly spaced
Ruby Basic: Exercise-55 with Solution
Write a Ruby program to check three given integers (one of them is small, one is medium and one is large) and return true if the three values are evenly spaced, so the difference between small and medium is the same as the difference between medium and large.
def check_num(a, b, c) if(b > a) temp = a a = b b = temp end if(c > b) temp = b b =c c = temp end if(b > a) temp = a a = b b = temp end return(a - b == b - c) end print check_num(5, 10, 15),"\n" print check_num(2, 3, 11),"\n"
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to check three given integers x, y, z and return true if one of y or z is close (differing from a by at most 1), while the other is far, differing from both other values by 3 or more.
Next: Ruby Array Exercises
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework