Compute the Average

  • + 0 comments
    #!/bin/bash
    
    read n
    str="0"
    
    # for i in {0..$n};
    for ((i=0; i<$n; ++i));
    do
        read a
        str="$str+$a"
    done
    echo "($str)/$n" | bc -l | xargs printf "%.3f"