Question: Building on the provided code in this tasks resources, write a recursive function that calculates a factorial using recursion. The program will take a number
Building on the provided code in this tasks resources, write a recursive function that calculates a factorial using recursion.
The program will take a number on the command line and calculate the factorial for that number.
Please provide the full code as the final answer. Any changes or deviation (including the code not working) to this request will be reported.
Provided Code:
recursive_factorial.rb: # Recursive Factorial
# Complete the following
def factorial(n)
end
# Add to the following code to prevent errors for ARGV[0]
def main
puts factorial(ARGV[0].to_i)
end
main
Building on the provided code in this task's resources, write a recursive function that calculates a factorial using recursion. The program will take a number on the command line and calculate the factorial for that number. ARGV: Command Line Arguments with ARGV Click here for more details You also need to put in a check-in case an incorrect argument is passed in. You will need to include the following line of puts("Incorrect argument - need a single argument with a value of 0 or more ") Submit your code and upload your tests as screen shots to the workspace
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
