reverse an integer

i have created a script that will reverse any given ineter.

#!/bin/ksh

echo "Enter the number"
read n

if [ $n -gt 0 ]
then
a=`expr $n / 10`
b=`expr $n % 10`
c=`expr $b \* 10 + $a`
fi
echo $c
---------------------------------------------------------------------

the problem with this script is that it only gives o/p for 2 digit number.

Can anyone help me in modifying this script that it will give o/p for any number of digit
.

#!/bin/ksh

echo "Enter the number"
read n
c=0
while [ $n -gt 0 ]
do
a=`expr $n % 10 `
n=`expr $n / 10 `
c=`expr $c \* 10 + $a`
done
echo $c

Thanks
Penchal

Thanks a lot for ur help dear. If possible can u tell me why there is a problem with my script...........

perl -nle 'print scalar reverse'

The "scalar" is necessary for making reverse operate on a string; by default, it reverses a list.

there must be loop( while) instead of condition (if)

In the last two lines there is logic problem

b=`expr $n % 10`
c=`expr $b \* 10 + $a`

Thanks
Penchal