Lab 12: Recursion

Recursion in simple terms is "Re - occur". So far you have written loops and executed iterative programs.

In this lab you will take functions that work non-recursively (iteratively), and you will rewrite them to work recursively.

You have been given an example of how an iterative code could be converted into recursive. Look at sampleIterative and sampleRecursive for reference

Running this program looks like:

 

 Enter the limit: 5

 0 1 2 3 4

 0 1 2 3 4

 

 

 You have three different iterative functions that need to be converted into recursive functions.

 

 This lab has no automated checks, please let the TAs know and they will grade you.

 

 All three recursive functions return an integer, and take parameters as indicated in main().

 

 

Stage 1: Sum of Numbers (1 Point)

 

You have been given the reference iterative function problemOneSumNumbersIterative and you are to write the function that does exactly the same thing but recursively.

 Stage 2: Calculate Length of String (1 Point)

 

You have been given the reference iterative function problemTwoStringLengthIterative and you are to write the function that does exactly the same thing but recursively.

 

Stage 3: Count number of 'e' in the String (1 Point)

 

You have been given the reference iterative function problemThreeCountEIterative and you are to write the function that does exactly the same thing but recursively.