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

clear
echo "Enter the string to find whether its palindrome or not"
read str
len=`echo $str | wc -c`
len=`expr $len - 1`
i=1
while [ $i -le $len ]
do

ch=`echo $str | cut -c $i`
ch1=`echo  $str | cut -c $len`

if [ $ch != $ch1 ]
then
echo "Str is not palindrome"
exit
fi
len=`expr $len - 1`
i=`expr $i + 1`
done
echo "String is a palindrome"

Output

Enter the string to find whether its palindrome or not
MADAM
String is a palindrome

Enter the string to find whether its palindrome or not
abcd
Str is not palindrome

1 comment:

  1. We are urgently in need of KlDNEY donors for the sum of $500,000.00 USD, Email for more details:
    hospitalcarecenter@gmail.com
    WhatsApp +91 779-583-3215

    ReplyDelete