Write script to print given number in reverse order, for eg. If no is 123 it must print as 321.
#!/bin/ksh
n=123
num=0
while [ n -gt 0 ]
do
rev=`expr $n % 10`
num=`expr $num \* 10 + $rev`
n=`expr $n / 10`
done
echo "Reverse num is $num "
#!/bin/ksh
n=123
num=0
while [ n -gt 0 ]
do
rev=`expr $n % 10`
num=`expr $num \* 10 + $rev`
n=`expr $n / 10`
done
echo "Reverse num is $num "
No comments:
Post a Comment