首页 > 解决方案 > 数字平均值(Bc 命令未找到错误)

问题描述

我想找出给定数字的平均值,但下面的代码显示了我:

main.bash:第 8 行:bc:找不到命令

请大家帮我看看我错在哪里?

代码片段:

read count
sum=0
for((i=0;i<count;i++))
do
    read var
    sum=`expr $sum + $var`
done
res=`echo "$sum / $count" | bc -l` 
printf "%.3f" $res 

标签: bash

解决方案


运行type -a bc,如果它返回:

-bash: type: bc: not found

然后,您必须在系统中安装bc软件包。


推荐阅读