next up previous
Up: APS105S Monday Quiz 1 Previous: 2 Modules

3 Recursive Functions

A palindrome is a word that is spelled the same backwards as forwards. For example the name ``hannah'' is a palindrome as is the word ``dad''.

Write a recursive function that takes a string as input and returns the boolean value true if the string is a palindrome, and false if it is not.

It is a requirement that the function be recursive.

Put your function into a complete Turing program that continuously reads in a string, and calls the function for each string to see if it is a palindrome. For each string the program should indicate if the word is a palindrome or not. The program should terminate when the string ``done'' is given as input. It should displays the result in the following way:

Input:  principle
Output: principle is not a palindrome

Input:  hannah
Output: hannah is a palindrome

Input:  done
Output: <program exits>

Restrictions:

The function you write must be recursive. No marks will be given for a non-recursive implementation.

Hint:

Recall that the function length(s) returns the number (an integer) of characters in the string s. A solution


Jonathan Rose
Sat Mar 8 17:17:46 EST 1997