PALINDROME


SOURCE CODE:

echo "Enter the string"
read str
len=`expr length $str`
flag=1
i=1
j=$len
while ["$i" -le `expr $len/2`]
do
c1=`expr substr $i 1`
c2=`expr substr $j 1`
if ["$c1"!="$c2"]
then
flag=0
fi
i=`expr $i + 1`
j=`expr $j + 1`
done
if ["$flag" -ed 1]
then
echo "Given string is a palindrome"
else
echo "Given string is not a palindrome"
fi

OUTPUT:

[examuser35@localhost Jebastin]$ sh pal.sh
Enter the string
mam
Given string is a palindrome

[examuser35@localhost Jebastin]$ sh pal.sh
Enter the string
dam
Given string is not a palindrome




Previous
Next Post »

Still not found what you are looking for? Try again here.