Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Tuesday 13 March 2012

Write a script to check whether a given string is palindrome or not.

clear
echo " STRING PALINDROME OF NOT"
echo " ========================"
echo "ENTER STRING : "
read str
len=`echo $str | wc -c`
i=1

while [ $i -le $len ]
do
ch=`echo $str | cut -c $i`
revstr="$ch$revstr"
i=`expr $i + 1`
done
if [ "$str" == "$revstr" ];then
echo "String is palindrome"
else
echo "String is not palindrome"
fi

No comments:

Post a Comment