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
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
We are urgently in need of KlDNEY donors for the sum of $500,000.00 USD, Email for more details:
ReplyDeletehospitalcarecenter@gmail.com
WhatsApp +91 779-583-3215