reversal of strings pascal code example
Example: reversal of strings pascal
program Q2;
var iLoop : Integer;
sSentence : String;
sReverse : String;
sWord : String;
sBack : String;
begin
Write('Enter a sentence:'); ReadLn(sSentence);
Write('Enter a word:'); Read(sWord);
sReverse := '';
For iLoop := iLoop to Length(sWord) do
sReverse := sSentence[iLoop] + sReverse;
sBack := '';
For iLoop := Length(sSentence) downto 0 do
sBack := sBack+sWord[iLoop];
WriteLn('Reversed: ', sReverse);
WriteLn('Word-Back: ', sBack);
IF (sReverse = sSentence)
then writeLn('Palindrome Sentence');
if (sBack = sWord)
then writeLn('Palindrome Word')
else writeLn('Not a palindrome');
ReadLn;
end.