Lab #10: Recursion
Please write recursive solutions to the following problems (choose two):
1. Palindrome: Write a recursive function that determines whether or not a string is a palindrome. The empty string is a palindrome, as is any string containing only one character. Any longer string is a palindrome if its first and last characters match, and if the string formed by removing the first and last characters is also a palindrome.
Write a main method that reads a string from the user. Use your recursive function to determine whether or not the string is a palindrome. Then display an appropriate message for the user.
2. Fibonacci: Write a recursive function that computes the nth number in the Fibonacci sequence. The Fibonacci sequence starts with two 1's. 1, 1, and the remaining numbers are the result of adding the two previous numbers. 1,1,2,3,5,8,13,21...
Write a main method that asks the user to enter the number of the sequence to compute. Use your function to compute that number in the sequence (for example, if the user entered 6, your function would return 8 because that is the 6th number in the sequence), and display the result with an appropriate message.
3. Factorial: Write a recursive function to compute the factorial of a number. The factorial of a number is that number times itself -1 until you get to 1. For example:
1! = 1
2! = 2 * 1! = 2 * 1 = 2
3! = 3 * 2! = 3 * 2 * 1! = 3 * 2 * 1 = 6
4! = 4 * 3! = 4 * 3 * 2! = 4 * 3 * 2 * 1! = 4 * 3 * 2 * 1 = 12
Write a main method that allows the user to enter a number. Use your function to compute the factorial of that number and display the result with an appropriate message.