Skip to content

Instantly share code, notes, and snippets.

@chiragmongia
Created July 31, 2013 07:22
Show Gist options
  • Select an option

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

Select an option

Save chiragmongia/6120001 to your computer and use it in GitHub Desktop.
def factorial(num)
if num > 0
"Factorial is: #{(1..num).inject(:*)}"
else
"Number should be greater than zero"
end
end
p "Factorial Using Ranges"
print "Enter the number: "
num = gets.to_i
p factorial(num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment