Written by Sai Sandeep Thota on February 27, 2013 in Programming > Shell

Shell Script to Reverse a Number

GET ALERTS:

Get our Latest updates delivered to your mailbox!

This article will discuss about Shell Program to Reverse a Number. Reversing a Number program follows the same logic of a Palindrome program, but here we will not check the condition whether the given number is Palindrome or not.

Shell Program to Reverse a Number

echo "Enter a Number:"
read a

rev=0
sd=0
or=$a

while [ $a -gt 0 ]
do
        sd=`expr $a % 10`
        temp=`expr $rev \* 10`
        rev=`expr $temp + $sd`
        a=`expr $a / 10`
done

echo "Reverse of $or is $rev"

Output:
reverse

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: