Averages/Arithmetic mean: Difference between revisions
Content added Content deleted
m (Lang tags) |
m (→{{header|UnixPipes}}: Lang tags) |
||
Line 686: | Line 686: | ||
=={{header|UnixPipes}}== |
=={{header|UnixPipes}}== |
||
<lang bash>term() { |
|||
b=$1;res=$2 |
|||
echo "scale=5;$res+$b" | bc |
|||
}</lang> |
|||
} |
|||
<lang bash>sum() { |
|||
(read B; res=$1; |
|||
test -n "$B" && (term $B $res) || (term 0 $res)) |
|||
}</lang> |
|||
} |
|||
<lang bash>fold() { |
|||
func=$1 |
|||
(while read a ; do |
|||
fold $func | $func $a |
|||
done) |
|||
}</lang> |
|||
} |
|||
<lang bash>mean() { |
|||
tee >(wc -l > count) | fold sum | xargs echo "scale=5;(1/" $(cat count) ") * " | bc |
|||
}</lang> |
|||
} |
|||
⚫ | |||
⚫ | |||
=={{header|V}}== |
=={{header|V}}== |