Problems Requiring the Writing of Recursive Functions The following problems will give you an excellent opportunity to hone your recursive skills. Some of these problems are harder than others, and one of the skills you need to develop is being able to get a sense of how "hard" a problem is, recursive or otherwise. Another thing to be on the lookout for here, as always, is which function should be a value- returning function and which should be void function. The wording of the problem is your best clue. In either case, be sure to name the function appropriately. ----- Problem ---------------------------------------------------------- Write a recursive function which takes as input a positive integer and returns a new integer which is the input integer with every two digits reversed. The function should regard every integer as containing an even number of digits, so that if an integer contains an odd number of digits, it's as though the integer contained a leading 0. For example, the integer 123 would be viewed as 0123. Examples: For an input of 123456 the the return value would be 214365. For an input of 291 the return value would be 2019. For an input of 4 the return value would be 40. ----- Problem ---------------------------------------------------------- Write a recursive function that takes as input a positive integer and writes out an integer whose digits are those of the input integer written backwards and then forwards. Examples: For an input of 12345678 the output would be 8765432112345678. For an input of 30 the output would be 0330. ----- Problem ---------------------------------------------------------- Write a recursive function that takes as input a positive integer and writes out an integer whose digits are those of the input integer written forwards and then backwards. Examples: For an input of 123456 the output would be 123456654321. For an input of 30 the output would be 3003. For an input of 6 the output would be 66. ----- Problem ---------------------------------------------------------- Write a recursive function that reads up to a full line of characters and echoes (i.e., prints out) only those which are capitals. Example: For an input of The US and CANADA belong to NATO. the output would be: TUSCANADANATO ----- Problem ---------------------------------------------------------- Write a recursive function that takes as input a positive decimal integer (i.e., an integer written "as usual" in base 10) and returns the equivalent of this integer written in base 3. Examples: For an input of 23 the return value would be 212. For an input of 85 the return value would be 10011. For an input of 8 the return value would be 22. ----- Problem ---------------------------------------------------------- Write a recursive function that takes as input a single positive integer and writes out an integer whose digits are formed by squaring the digits of the input integer and writing out the resulting values in reverse. Examples: For an input of 123 the return value would be 941. For an input of 4251 the return value would be 125416. For an input of 30 the return value would be 09. ----- Problem ---------------------------------------------------------- Write a recursive function that takes as input a single positive integer and returns the number of even digits in the integer. Examples: For an input of 123456 the function would return the value 3. For an input of 24262 the function would return the value 5. For an input of 3157395 the function would return the value 0. ----- Problem ---------------------------------------------------------- Write a recursive function that takes as input a single positive integer and writes out another integer whose digits are the odd digits contained in the input integer, in the same order. Examples: For an input of 1234 the output would be 13. For an input of 13573 the output would be 13573. For an input of 246367 the output would be 37. ----- Problem ---------------------------------------------------------- Write a recursive boolean function called isPalindrome that will take as input a single positive integer and return "true" if the integer is a palindrome and "false" otherwise. Examples: For an input of 6 the return value would be "true". For an input of 4731374 the return value would be "true". For an input of 64 the return value would be "false". For an input of 12331 the return value would be "false". For an input of 1234322 the return value would be "false".