Sum and product of an array: Difference between revisions

(split Lisp section into Common Lisp (touch up existing section) and Emacs Lisp; rm common lisp Works-with because Works-with should be for impl-specific stuff)
Line 109:
set product to product * i
end repeat
 
=={{header|AWK}}==
For array input, it is easiest to "deserialize" it from a string with the split() function.
<lang awk>
$ awk 'func sum(s){split(s,a);r=0;for(i in a)r+=a[i];return r}{print sum($0)}'
1 2 3 4 5 6 7 8 9 10
55
 
$ awk 'func prod(s){split(s,a);r=1;for(i in a)r*=a[i];return r}{print prod($0)}'
1 2 3 4 5 6 7 8 9 10
3628800
</lang>
 
=={{header|BASIC}}==
Anonymous user