Code In Tech - The Ultimate World of Computer Technology

Monday, 4 June 2012

Shell script to display the digits in odd position from the given five digit no.

SOURCE CODE:

echo “Enter the string of the five nos.”
read n
i=1
a=” ”
while [ $i –le 5]
do
     o=`echo $n | cut –c $i`
     s=$s$a$o
i=`expr $i + 2`
    done

     echo “nos. at odd positions:“ $s

OUTPUT: 

Enter the string of the five nos.
2 5 8 4 9
nos. at odd positions:
2 8 9 

2 comments :