9.2
Anonymous
ruby
10/26/2023 12:11 PM
448 B
22
Indexable
# Recursive Factorial
# Complete the following
def factorial(n)
if n <= 1
return 1
else
return n * factorial(n - 1)
end
end
def main
if ARGV[0].to_i < 0
puts("Incorrect argument - need a single argument with a value of 0 or more.\n")
else
puts (factorial(ARGV[0].to_i))
end
end
main
Editor is loading...