Skip to content

Instantly share code, notes, and snippets.

@fenixbrassi
Created December 14, 2013 02:50
Show Gist options
  • Save fenixbrassi/7955154 to your computer and use it in GitHub Desktop.
Save fenixbrassi/7955154 to your computer and use it in GitHub Desktop.
Leap years program
#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