A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Factorial in Crystal page! Here, you'll find the source code for this program as well as a description of how the program works.
begin
if ARGV.empty?
raise "Usage: please input a non-negative integer"
end
input = ARGV[0].to_i?
if input.nil?
raise "Usage: please input a non-negative integer"
end
input = input.not_nil!
if input >= 0 && input <= 12
puts factorial(input)
elsif input > 12
raise "#{input} is out of the reasonable bounds for calculation."
else
raise "Usage: please input a non-negative integer"
end
rescue e
puts e.message
end
def factorial(n)
return 1 if n == 0
n * factorial(n - 1)
end
Factorial in Crystal 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.