Shell Programming - Looping - Reverse of a number

# Shell Programming
# Reverse a number
echo -n "Enter a number : "
read n
ori=$n
i=0

while [ $n -gt 10 ]
do
mod=`expr $n % 10`
i=`expr $i \* 10 + $mod`
n=`expr $n / 10`
done

i=`expr $i \* 10 + $n`
echo "Entered Number : $ori"
echo "Reversed Number : $i"

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu