Saturday, 16 July 2016

Write a shell script in Linux/Unix to find the Reverse of a number and check whether the number is Palindrome or not.


echo "ENTER A NUMBER-"
read n
rev=0
t=$n
while test $n -ne 0
do
r=`expr $n % 10`
rev=`expr $rev \* 10`
rev=`expr $rev + $r`
n=`expr $n / 10`
done
echo "THE REVERSE IS-$rev"
if test $rev -eq $t
then
echo "THE NUMBER IS PALINDROME"
else
echo "THE NUMBER IS NOT PALINDROME"
fi


OUTPUT:

ENTER A NUMBER-
121
THE REVERSE IS-121
THE NUMBER IS PALINDROME







No comments:

Post a Comment

Popular Posts