Question:

Write a shell script to print given number in reverse order in Unix?

by Guest378  |  earlier

0 LIKES UnLike

 Tags:

   Report

1 ANSWERS


  1. if [ $# -ne 1 ]
    then
    echo "Usage: $0 number"
    echo " I will find reverse of given number"
    echo " For eg. $0 123, I will print 321"
    exit 1
    fi

    n=$1
    rev=0
    sd=0

    while [ $n -gt 0 ]
    do
    sd=`expr $n % 10`
    rev=`expr $rev \* 10 + $sd`
    n=`expr $n / 10`
    done
    echo "Reverse number is $rev"

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.