#Shell script to add the numbers divisible by 3 in the range 50 to 100
s=0
for((i=50;i<=100;i++))
do
if [ `expr $i % 3` = 0 ]
then
echo "$i "
s=`expr $s + $i`
fi
done
echo "Sum of the numbers divisible by 3 between 50 to 100 is $s"
OUTPUT
csc@csc-SVE1513CYNB ~ $ bash sumdiv.sh
51
54
57
60
63
66
69
72
75
78
81
84
87
90
93
96
99
Sum of the numbers divisible by 3 between 50 to 100 is 1275
s=0
for((i=50;i<=100;i++))
do
if [ `expr $i % 3` = 0 ]
then
echo "$i "
s=`expr $s + $i`
fi
done
echo "Sum of the numbers divisible by 3 between 50 to 100 is $s"
OUTPUT
csc@csc-SVE1513CYNB ~ $ bash sumdiv.sh
51
54
57
60
63
66
69
72
75
78
81
84
87
90
93
96
99
Sum of the numbers divisible by 3 between 50 to 100 is 1275
No comments:
Post a Comment