Write a shell script to print 1 to 20 no’s in reverse and also calculate the sum of odd nos.

echo "Print no 1 to 20 in reverse"
no=20
while [ $no -ge 1 ]
do
	echo $no
	temp=` expr $no % 2 `
	if [ $temp -eq 1 ]
	then
		c=` expr $c + $no `
	fi
	no=` expr $no - 1 `
done
echo "Sum of odd number is $c"

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *