Logo 
Search:

Dos Articles

Submit Article
Home » Articles » Dos » ScriptsRSS Feeds

Palindrome string

Posted By: Huberta Miller     Category: Dos     Views: 4509

Script to check given string is palindrome or not.

Code for Palindrome string in Dos

echo Enter String
read str

    length=0
    cnt=1
    flag=0

length=`expr $str | wc -c`
length=`expr $length - 1`
temp=`expr $length / 2`

while test $cnt -le $temp
do
        rev=`expr $str | cut -c $cnt`
        ans=`expr $str | cut -c $length`

        if [ $rev != $ans ]
        then
                flag=1
        fi

        cnt=`expr $cnt + 1`
        length=`expr $length - 1`
done

if [ $flag -eq 0 ]
then
        echo String is palindrome
else
        echo String is not palindrome
fi
  
Share: 


Didn't find what you were looking for? Find more on Palindrome string Or get search suggestion and latest updates.

Huberta Miller
Huberta Miller author of Palindrome string is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!