9.2

mail@pastecode.io avatar
unknown
ruby
a year ago
334 B
1
Indexable
Never
# 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