A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Factorial in Ruby page! Here, you'll find the source code for this program as well as a description of how the program works.
# return factorial of a non-negative number
if ARGV.empty?
puts "Usage: please input a non-negative integer"
exit
else
begin
string1 = ARGV[0]
num = Integer(string1)
rescue ArgumentError
puts "Usage: please input a non-negative integer"
exit
end
if num < 0
puts "Usage: please input a non-negative integer"
exit
end
i = 1
factorial = 1
while i <= num
factorial = factorial * i
i += 1
end
print(factorial)
end
Factorial in Ruby was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.