program ex38;
var
s, r : string;
i, c, k :integer;
begin
writeln ('Enter a string');
readln (s);
r := s;
c:= length(s);
for i := length(s) downto 1 do
write (s[i]);
for k := 1 to length(s) do
begin
r[k] := s[c];
dec(c);
end;
writeln;
if s = r then writeln ('Palindrome!');
writeln;
readln;
end.
We read a string, copy it to another string and then write it out backwards. We then set the copy to be the reverse of the original, so in a 5-character string:
r[5] becomes s[1]
r[4] becomes s[2]
r[3] becomes s[3]
r[2] becomes s[4]
r[1] becomes s[5]
Now the copy is reversed we can compare it with the original to see if it is the same, if it is it's the same.
What is the palindrome of Bolton? It doesn't work! It must be a pun!