Created
November 10, 2015 19:59
-
-
Save kylekeesling/26ab35c7ed15f04bb343 to your computer and use it in GitHub Desktop.
Leap Year Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Enter a starting year in the format YYYY" | |
starting = gets.chomp!.to_i | |
puts "Enter an ending year in the format YYYY" | |
ending = gets.chomp!.to_i | |
puts "LEAP YEARS between #{starting} and #{ending}" | |
starting.upto(ending) do |year| | |
divisible_by_4 = (year % 4) == 0 | |
not_divisible_by_100 = (year % 100) != 0 | |
divisible_by_400 = (year % 400) == 0 | |
is_leap_year = (divisible_by_4 && not_divisible_by_100) || divisible_by_400 | |
if is_leap_year | |
puts "#{year}" | |
end | |
end |
Author
kylekeesling
commented
Nov 10, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment