Lab 11 : Recursion
July 29, 2020
Submit your code to Gradescope
For this lab, the TAs need to manually go through your code to check if your functions are using recursion properly. When you are finished, download your code from Zybooks then submit it to Gradescope, and the TAs will grade you there. Note that in order to be graded, for each step, your code must pass all the corresponding Zybooks tests ( i.e., test 1 and 2 for stage 1, and test 3 for stage 2).
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.
Three properties of recursive functions:
You have two different iterative functions that need to be converted into recursive functions. All two recursive functions return an integer, and take parameters as indicated in main().
Stage 1: Display Odd Numbers(2 Point)
You have been given the reference iterative function problemOneOddNumbersIterative , this function takes a number as input and displays all the odd numbers smaller than this number. You are to write the function that does exactly the same thing but recursively.
Stage 2: Count Upper case alphabets (1 Point: Extra Credit)
You have been given the reference iterative function problemTwoCountUpperRecursive , this function takes a string as input and counts the number of upper case alphabets in it. You are to write the function that does exactly the same thing but recursively.
For this lab, the TAs need to manually go through your code to check if your functions are using recursion properly. When you are finished, download your code from Zybooks then submit it to Gradescope, and the TAs will grade you there. Note that in order to be graded, for each step, your code must pass all the corresponding Zybooks tests ( i.e., test 1 and 2 for stage 1, and test 3 for stage 2).
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.
Three properties of recursive functions:
- Recursive functions do not have loops
- They call themselves
- Have an exit condition so they can stop calling themselves.
Enter the limit: 5 0 1 2 3 4 0 1 2 3 4
You have two different iterative functions that need to be converted into recursive functions. All two recursive functions return an integer, and take parameters as indicated in main().
Stage 1: Display Odd Numbers(2 Point)
You have been given the reference iterative function problemOneOddNumbersIterative , this function takes a number as input and displays all the odd numbers smaller than this number. You are to write the function that does exactly the same thing but recursively.
Stage 2: Count Upper case alphabets (1 Point: Extra Credit)
You have been given the reference iterative function problemTwoCountUpperRecursive , this function takes a string as input and counts the number of upper case alphabets in it. You are to write the function that does exactly the same thing but recursively.