Code In Tech - The Ultimate World of Computer Technology

Saturday 12 May 2012

Shell script to reverse a string.

SOURCE CODE:

echo “Enter the string”
read str
l=`expr length $str`
a=1
r=$l
while [ $a –le $r ]
do
     s=`expr $str | cut –c $l`
     l=`expr $l – 1`
     a=`expr $a + 1`
done
echo $s

OUTPUT:

Enter the string:
HELLO
OLLEH  

No comments :

Post a Comment