The task is that if input numbers:
4
1
2
9
8
Output=(sum of all except first_number_in_series)/first_number in series
Then output average should be 1+2+9+8/(first_number_in series)=20/4=5
I have tried the following code, however not able to achieve the task. I will be grateful if anyone can point out the mistake.
#!/bin/bash
sum=0
count=1
for x in $*
do
if [ $count -eq 1 ]
then
p=$x
else
sum=$(($sum + $x))
fi
((count++))
done
echo "scale=3;$sum/$p" | bc