Sei sulla pagina 1di 1

Note: The following is pseudo-code (I tried to make it as close to code as possible) Because there are so many programming languages

it would not be good to answer this question with one language. So, you should be able to take this pseudo-code and finish it in your language. This is very close to C. integer palindrome(char[] string) { if (length(string) == 1)) /* if there is only 1 character left then it is a palindrone */ return 1 (true) if (string[0] == string[length(string)-1]) { /* create newstring from string[1] to string[lengthstring)-2] */ for (i=1 to length(string)-2) newstring[i-1]=string[i]; if (length(string)-2 == 0) /* we are looking at the last 2 characters return 1 (true) palendrome(newstring[]); /* Call palindrone again with two less characters */ } return 0 (false) }

Potrebbero piacerti anche