Ruby – Factorial

Filed under ruby
Tagged as , , ,

Author: slac3dork
Site: http://slac3dork.110mb.com
Summary:Ruby code to get factorial value. Tested on Linux.
Usage: ruby factorial.rb <your_value> or ./factorial.rb <your_value>

#!/usb/bin/ruby

#  _________      .__       .____   _______
# /   _____/ ____ |__|_____ |    |  \   _  \    ____
# \_____  \ /    \|  \____ \|    |  /  /_\  \  / ___\
# /        \   |  \  |  |_> >    |__\  \_/   \/ /_/  >
#/_______  /___|  /__|   __/|_______ \_____  /\___  /
#        \/     \/   |__|           \/     \//_____/
# http://snippet.c0de.me
# slac3dork@gmail.com

def fact(n)
	if n == 0
		1
	else
		n * fact(n-1)
	end
end
print "factorial.rb - Get Factorial value\n"
print "usage: ./factorial.rb <your_value>\n"
print "Coded By slac3dork\n\n"
print "Factorial Value of ",ARGV[0].to_i," = ",fact(ARGV[0].to_i), "\n"

ruby,code,code,snippet

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*