Basic script to calculate the average, asking numbers in the terminal
read Nx
i=0
x=0
while [ $i -lt $Nx ]; do
read y
let x=$x+$y
let i=$i+1
done
result=$x/$i
echo "${result}" | bc -l | xargs printf "%.3f"
Basic script to calculate the average, asking numbers in the terminal
read Nx
i=0
x=0
while [ $i -lt $Nx ]; do
read y
let x=$x+$y
let i=$i+1
done
result=$x/$i
echo "${result}" | bc -l | xargs printf "%.3f"
You must be logged in to post a comment.
Great example.