题解 | #求平均值#
求平均值
https://www.nowcoder.com/practice/c44b98aeaf9942d3a61548bff306a7de
#!/bin/bash
declare -i sum=0
declare -i n=0
while read num
do
if (($n==0))
then
declare -i len=$num
else
let sum+=$num
fi
let n+=1
done
avg=$(awk "BEGIN {printf \"%.3f\", $sum / $len}")
echo $avg
