Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This lecture reviews how to write recursive functions. For (3) and (4), you'll need to fill in a function declaration, function call, and function definition
This lecture reviews how to write recursive functions. For (3) and (4), you'll need to fill in a function declaration, function call, and function definition (1) Make a function call to recursiveHelloWorld() and observe what happens (2) Modify the recursiveHelloWorld function, so the program can control how many "Hello World!" to print. The program will end after outputting the last Hello World! For example, if we call recursiveHello World(5), the program outputs "Hello World!" for five times and successfully ends. Hint: think about what the base case is, and how to modify the recursive function call. Hello world! Hello World! Hello world! Hello world! Hello world! (3) Write a function, i.e., factorial, to calculate the factorial of a positive integer. Use a loop in the function to do it. Assuming only positive integers are passed in. For example, a function call to factorial(5) calculates 5! = 120. 5! = 120 (4) Write a recursive version of factorial function instead of using a loop, called recursiveFactorial. Hint: Base case: when the number is 1, the product is 1; Recursive case: 5! = 5* 4!, 4! = 4*3!, etc
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started