#!/usr/bin/env bash function solution_1() { read count local sum=0 local loop=${count} while (( ${loop} > 0)); do read m sum=$((${sum}+${m})) loop=$((${loop}-1)) done echo "scale=3; ${sum}/${count}" | bc } function solution_2() { read count local sum=0 local loop=1 while (( ${loop} <= ${count})); do read m ((sum+=m)) ((loop++)) done echo "scale=3; ${sum}/${count}" | bc } function solution_3() { awk 'NR==1{all=$0} NR>1{total+=$0} END{printf "%.3f" ,total/all}' } function solution_4() { read -p '请输入数组长度:' len i=1 while [ $i -le $len ] do read -p '请输入数组数字:' num[$i] let i++ done for i in ${num[*]} do sum=$((sum+i)) done echo "scale=3; ${sum}/${len}" | bc #awk -va=$sum -vb=$len 'BEGIN{printf "%.3f\n",a / b }' } function solution_999() { read n sum=0 read m arr=($m) for ele in ${arr{@}}; do sum=$((${sum}+${ele})) done echo "scale=3; ${sum}/${n}" | bc } solution_1