Created
December 14, 2013 02:50
-
-
Save fenixbrassi/7955154 to your computer and use it in GitHub Desktop.
Leap years program
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
#Write a program that asks fro a starting year | |
#and ending year and then put all leap years | |
#between them including them if they are leap years | |
puts "Give me the start year" | |
start_year = gets | |
puts "Give me the end year" | |
end_year = gets | |
leap_years = [] | |
(start_year.to_i..end_year.to_i).each do |x| | |
if x % 4 == 0 | |
if x % 100 == 0 | |
if x % 400 == 0 | |
leap_years << x | |
end | |
else | |
leap_years << x | |
end | |
end | |
end | |
puts leap_years | |
-------------------- | |
Result in console: | |
Give me the start year | |
2013 | |
Give me the end year | |
2032 | |
2016 | |
2020 | |
2024 | |
2028 | |
2032 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment