Skip to content

Instantly share code, notes, and snippets.

@kylekeesling
Created November 10, 2015 19:59
Show Gist options
  • Save kylekeesling/26ab35c7ed15f04bb343 to your computer and use it in GitHub Desktop.
Save kylekeesling/26ab35c7ed15f04bb343 to your computer and use it in GitHub Desktop.
Leap Year Calculator
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
@kylekeesling
Copy link
Author

calculate_leap_year_-_google_search

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment