Sunday, February 14, 2016

Palindrome Program in Pascal


A simple program that I wrote before in Pascal to check if the word given by the user is a Palindrome or not a Palindrome. The code is very simple and easy to understand.


If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Program Listing


Program Palindrome;
Uses Crt;
Label Finish;
VAR
StrIn, dForward, Reversed:String;
n:Integer;
ch:Char;
Palin:Boolean;
Begin
     Clrscr;
     Writeln; Writeln; Writeln;
     Write('              PALINDROME PROGRAM IN PASCAL        ');
     Writeln(' Just Press Enter to quit the Program');
     Repeat
           Writeln;
           Write('Enter a Word :==> ');
           Readln(StrIn);
           If StrIn = '' Then Goto Finis;
           dForward := '';  Reversed := '';
               For n := 1 to Length(StrIn) Do
           Begin
                ch := UpCase(StrIn[n]);
                If ch in ['A'..'Z'] Then
                Begin
                     dForward := dForward + ch;
                     Reversed := ch + Reversed
                End;
           End;
           Palin := dForward = Reversed;  
           If Palin then Writeln('"',StrIn, '" is a palindrome.') 
           Else Writeln('"',StrIn, '" is not a palindrome.'); 
Finish: 
     Until StrIn = ''; 
END.

1 comment:


  1. Var
    y: String;
    Var
    i,z : Integer;
    Begin
    Writeln('Enter your word');
    Readln(y);
    //writeln(y[0]);
    //writeln(Length(y));
    Write('Reversed word is- ') ;
    For i:=Length(y) Downto 1 Do
    Begin
    Write(y[i]);
    If (y[i]=y[Length(y)+1-i]) Then
    z := z+1;
    If (z=Length(y)) Then
    Writeln(' & Entered word is Palindrome');
    End;
    Readln;
    Readln;
    End.

    ReplyDelete