Skip to content

Instantly share code, notes, and snippets.

@woodie
Created January 21, 2013 19:24
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 woodie/4588539 to your computer and use it in GitHub Desktop.
Save woodie/4588539 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
def factoral(n)
begin
if n == 0
return 1
elsif n > 0
return factoral(n - 1) * n
else n < 0
abort("Sorry, no negative numbers please")
end
rescue
abort("Sorry, integers only please")
end
end
puts ""
puts "factoral of 5 if #{factoral(5)}"
#puts "factoral of -5 if #{factoral(-5)}"
puts "factoral of 'c' if #{factoral('c')}"
__END__
factoral of 5 if 120
Sorry, integers only please
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment