9.2
unknown
ruby
2 years ago
334 B
11
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...