Sum and product of an array: Difference between revisions

Content added Content deleted
(+Oz)
Line 595: Line 595:
done;
done;
echo $SUM $PROD
echo $SUM $PROD


=={{header|UnixPipes}}==
prod() {
(read B; res=$1; test -n "$B" && expr $res \* $B || echo $res)
}

sum() {
(read B; res=$1; test -n "$B" && expr $res + $B || echo $res)
}

fold() {
(func=$1; while read a ; do ; fold $func | $func $a done)
}


(echo 3; echo 1; echo 4;echo 1;echo 5;echo 9) | tee >(fold sum) >(fold prod) > /dev/null


=={{header|XSLT}}==
=={{header|XSLT}}==