Question: SET - 2 5 2 C Programming # 2 Homework 1 2 Recursion Part 1 Reading ( s ) : As needed. Recursive: a procedure
SET C Programming #
Homework Recursion Part
Readings: As needed.
Recursive: a procedure that calls itself.
Recursion: that act of a procedure calling itself.
Getting a procedure to call itself is easy. The tough part is getting it to stop.
Here is an example of a procedure that adds the whole numbers to
continued on the next page
Step
Type in the code in the above example and get it working. Be sure to follow all the coding standards eg comment blocks
Find out the maximum number of times a procedure can be called recursively on your machine. Put that number in comments somewhere. Tell me how much memory your computer has too because that can be limiting factor.
Write a procedure, AddNumbersInRange, that takes a starting value and a stop value as parameters. The procedure should recursively add all the numbers inclusive in the range.
Step
Write a procedure that will recursively find the factorial of a number.
The factorial of a number is written as number followed by an exclamation point. For example, the factorial of is written as To find the factorial of a number, multiple the number by the factorial of the number minus one. So the factorial of is equal to the factorial of which is factorial. The factorial of is equal to times the factorial of which is You do this until you get to the factorial of which is FN N FN where N and F
For example: F is
To do that with a For loop would be very easy:
intFactorial intNumber;
for intIndex intNumber; intIndex ; intIndex
intFactorial intFactorial intIndex ;
Calculate the factorial for values and display the results. Display the results in two columns. Left column and the right column
Find out number for which the largest factorial that can be computed with this method on your computer. Put that number in comments somewhere. BTW, its definitely NOT the same number as in step # The answer will surprise you or at least it should
Please dont search the internet for the answerscode You can find it very quickly but that would defeat the point of the exercise.
continued on the next page
Step
Write a procedure that will recursively find the Fibonacci value of a number.
The Fibonacci of a number is equal to the Fibonacci value of the number minus one plus the Fibonacci value of the number minus two. This is usually written as:
FN FN FN where N and F
The Fibonacci value of one and two is one.
For example: F is
F F F
F F F F
F F
Find out the number for which the largest Fibonacci value can be computed with this method on your computer. Put that number in comments somewhere.
MEGA EXTRA CREDIT
Find a magic square solution for a x square using recursion. You can search the internet to find out what a magic square is but dont search for code examples. You dont get extra credit for copying and pasting. Ill know just by asking you a few questions whether or not you did the work.
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
