Created
October 2, 2012 02:37
-
-
Save shoya140/3815857 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
#encoding: utf-8 | |
def is_perfect_number(number) | |
sum = 0 | |
for i in 1 .. number | |
if number % i == 0 then | |
sum = sum + i | |
end | |
end | |
if sum == 2 * number then | |
return true | |
else | |
return false | |
end | |
end | |
print "数値を入力してください:" | |
input_number = gets.to_i | |
print "1から#{input_number}までには" | |
hit = 0 | |
for i in 1 .. input_number | |
if is_perfect_number(i) == true then | |
print "#{i} " | |
hit = hit + 1 | |
end | |
end | |
if hit == 0 then | |
puts "完全数はありません" | |
else | |
puts "という完全数があります" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment