CHRIST MCA 2009-2012
Would you like to react to this message? Create an account in a few clicks or log in to continue.

2. Write a shell script to reverse a 5 digit number

Go down

2.	Write a shell script to reverse a 5 digit number Empty 2. Write a shell script to reverse a 5 digit number

Post  nibedita Wed Jul 21, 2010 9:11 pm

#1. Write a shell script to reverse a 5 digit number
clear
echo -n "Enter a number: "
read num
n=$num
newn=0
pow=10
while [ $n -ne 0 ]
do
k=`expr $n % 10`
newn=`expr $newn \* $pow`
newn=`expr $newn + $k`
n=`expr $n / 10`
done
echo "Reverse of $num is $newn"


Last edited by rakesh on Wed Jul 21, 2010 9:16 pm; edited 1 time in total (Reason for editing : prog number was incorrect. so i edited the heading)

nibedita

Posts : 3
Join date : 2010-07-21

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum