Shell program to find sum of odd numbers in a series

# Shell program to find sum of odd numbers in a series of 10 numbers
sum=0
i=0
while [ $i -ne 10 ]
do
echo "Enter Number"
read num
if [ `expr $num % 2` -ne 0 ]
then
sum=`expr $sum + $num`
fi
i=`expr $i + 1`
done
echo Sum of odd numbers = $sum

Output
————-

Enter Number
1
Enter Number
2
Enter Number
3
Enter Number
4
Enter Number
6
Enter Number
8
Enter Number
3
Enter Number
1
Enter Number
1
Enter Number
1
Sum of odd numbers = 10

VN:F [1.9.22_1171]
Rating: 3.4/10 (8 votes cast)
VN:F [1.9.22_1171]
Rating: +3 (from 3 votes)
Shell program to find sum of odd numbers in a series, 3.4 out of 10 based on 8 ratings

16. February 2009 by Jishnu
Categories: Shell Scripting | Tags: , | Leave a comment

Leave a Reply