Print numbers in the reverse order

Write a shell script that accept any number of arguments and print them in the reverse order

Questions by pankajforall2003

Showing Answers 1 - 12 of 12 Answers

Here you go ..

set NUMBER=1234 // Pass the number as you want .
set  REV=0 
set TMP_NUM=$NUMBER

while [ $NUMBER != $REV ]
do
     RMND = $TMP_NUM % 10 
     REV= $RMND + 10*$REV
     TMP_NUM=$TMP_NUM/10
  done
echo "The reverse Number is $REV"

  Was this answer useful?  Yes

This  the rt one ......

#!/usr/bin/ksh
typeset -i NUM=1234        //as u want
typeset -i TMP_NUM=$NUM

typeset -i  REV=0
while [ $NUM != 0  ]
do
   RMND=$NUM%10
   REV=$RMND+10*$REV
   NUM=$NUM/10
done

echo "Reverse  Number for Number $TMP_NUM is $REV"

  Was this answer useful?  Yes

Sonali Sehgal

  • Jan 14th, 2013
 

In PERL, we can reverse the string as follows:-

Code
  1. $x="12345678";

  Was this answer useful?  Yes

PREM

  • Jun 16th, 2014
 

PRINT A NUMBER IN REVERSE

Code
  1.        $echo "12345678" | rev

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions