Question: Exercise 1 : Factorials, done recursively. Create a function called factorial, defined as follows: int factorial ( int theNum ) ; This function should take
Exercise : Factorials, done recursively.
Create a function called factorial, defined as follows:
int factorialint theNum;
This function should take an integer argument and return an integer result. It should work as follows:
If given a number less than zero, it should return a value of representing an error.
If given a or it should return a value of
If given a number larger than it should compute the factorial of the number minus and
multiply it by that number. For example, for factorial it would return the product of times
factorial This is a direct analog to the idea of mathematical induction.
Don't use any for or while loops in your function; if done recursively, you don't need any.
It's and expected to use a for loop in main to test your function.
It is possible to do this in three lines of code and probably even fewer but this is not required.
Create a testbench program main and all that to test your factorial function. What is the highest
number for which it can correctly compute the factorial?
Now, replace all of your type int with type unsigned long long. Remember to do this for the function
parameters, as well as the individual variables. Also recall you will need llu" for the printf format.
Does your program work differently now? Does it work for larger numbers? What is going on
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
