Skip to content

Instantly share code, notes, and snippets.

@mikecmpbll
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikecmpbll/20e07db6495415c6a220 to your computer and use it in GitHub Desktop.
Save mikecmpbll/20e07db6495415c6a220 to your computer and use it in GitHub Desktop.
print "Enter an integer number to be calculated as factorial: "
Integer(gets) rescue print "Hey, that's not an integer! Enter an integer, please: "
n = gets.to_i
def factorial n
n > 1 ? n * factorial(n - 1) : 1
end
puts "Factorial of number #{n} is #{factorial(n)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment