Last active
December 20, 2015 20:28
-
-
Save Yamabiko/6190315 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# def はメソッドを定義するキーワードです。 | |
def factorial(n) | |
if n < 0 | |
return false | |
elsif n == 0 || n == 1 | |
return 1 | |
else | |
return n * factorial(n-1) | |
end | |
end | |
# main | |
n = gets.to_i | |
puts factorial(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment