01.AC的Shell

#!/bin/bash
read loop
sum=0 
count=0
for ((i = 0; i < $loop; ++i)) 
do 
    read temp
    ((sum+=temp))
    ((++count))
done
echo "scale=3;$sum/$count" | bc

02.差点AC的shell

  • 问题出在最后一行
    #!/bin/bash
    read loop
    sum=0 
    count=0
    for ((i = 0; i < $loop; ++i)) 
    do 
      read temp
      ((sum+=temp))
      ((++count))
    done
    echo "scale=3;$sum/$count" 

03.修改原先AC代码

  • 谢谢牛油@xxxxw 指出该处loop
#!/bin/bash
read loop
sum=0 
for ((i = 0; i < $loop; ++i)) 
do 
    read temp
    ((sum+=temp))
done
echo "scale=3;$sum/$loop" | bc