Last active
December 20, 2015 09:49
-
-
Save yucao24hours/6110489 to your computer and use it in GitHub Desktop.
入力されたふたつの年のあいだにある閏年を表示するプログラムです。
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 "Type the start year." | |
start_year = gets.chomp.to_i | |
puts "Then, type the end year." | |
end_year = gets.chomp.to_i | |
puts "==================================" | |
puts "The followings are the leap years." | |
puts "==================================" | |
i = start_year | |
while i <= end_year | |
if (i % 400) == 0 | |
# 400で割り切れればうるう年 | |
puts i | |
elsif i % 100 != 0 | |
# 400では割り切れない場合 | |
if i % 4 == 0 | |
# 100で割り切れず、4では割り切れればうるう年 | |
puts i | |
end | |
end | |
i = i + 1 | |
end | |
puts "==================================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
範囲に対して処理していることが明確になるように Range を使うとループがすっきりするかな。