Skip to content

Instantly share code, notes, and snippets.

@chiragmongia
Created March 17, 2013 17:46
Show Gist options
  • Select an option

  • Save chiragmongia/5182713 to your computer and use it in GitHub Desktop.

Select an option

Save chiragmongia/5182713 to your computer and use it in GitHub Desktop.
def factorial(num)
p (1..num).inject(:*) || 1
end
p "Factorial Using Ranges"
print "Enter the number: "
num = gets.to_i
print "Factorial is: "
factorial(num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment