Friday, 27 March 2015

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


2) Write a shell program to check whether a given number is palindrome or not?
clear
echo "Enter the number you want?"
read num
m=$num
rev=0
while [ $num -gt 0 ]
do
r=`expr $num % 10`
rev=`expr $rev \* 10 + $r`
num=`expr $num / 10`
done
if [ $m = $rev ]
then
echo " $m is Palindrome"
else
echo " $m is not Palindrome"
fi


No comments:

Post a Comment