Fortran程序出错:f90: Severe: The input stream is empty. error executing workdf.exe.

我刚开始学习fortran ,自己编了个最简单的小程序,但是出现错误,不知道为什么,哪位高手帮忙看看,谢啦_百度知道
我刚开始学习fortran ,自己编了个最简单的小程序,但是出现错误,不知道为什么,哪位高手帮忙看看,谢啦
D.exe.;example: Invalid argument,jREAD (*;工程软件安装包\Error executing df.f90f90,万分感谢呀;input_example_2\1¤3ìèí;MSDEV98\qita&#92,*) k?t°2×°°ü\MyProjects&#92:.D,lREAD (*;MSDEV98&#92PROGRAM input_example_2INTEGER .: input_example_2 - Win32 Debug--------------------Compiling Fortran.input_example_2;fortran&#92:\MyProjects&#92:&#92,*) i, 0 warning(s)各位高手给解答一下吧;input_example_2&#92..exe - 1 error(s);example. file is &#39: Severe:--------------------Configuration.f90&#39,k,j.;qita&#92,lEND PROGRAM input_example_2编译出来是这样的;fortran&#92: i
编译器不识别。建议把文件放在英文路径下;工程软件安装包这个路径是中文的:&#92D
哈哈,好了,谢谢呀。继续问一下,文件夹里出现这么写文件,分别都是干什么用的呢?呵呵,不好意思,初学呀
dsp 是 project 工程 文件。dsw 是 workspace 文件。f90 是源码文件。opt 是设置选项。plg 是编译日志(没什么用)。同一个 workspace 可以容纳一个或多个 project。同一个 project 可以容纳一个或多个源代码文件。
来自团队:
其他类似问题
为您推荐:
其他1条回答
input_example_2\fortran\工程软件安装包&#92,再编译;MSDEV98&#92,f90文件目录中不能出现中文名称。D.f90把这个f90文件放到纯英文目录下;example:\MyProjects\qita&#92文件名中出现了中午目录
fortran的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁From Rosetta Code
Sum and product of an array
You are encouraged to
according to the task description, using any language you may know.
Compute the sum and product of an array of integers.
ARRAY INTEGER($0)For ($i;1;5)
APPEND TO ARRAY($$i)End for $sum:=0$product:=1For ($i;1;Size of array($list))
$sum:=$var+$list{$i}
$product:=$product*$list{$i}End for // since 4D v13 $sum:=sum($list) 
(defun sum (xs)
(if (endp xs)
(+ (first xs)
(sum (rest xs))))) (defun prod (xs)
(if (endp xs)
(* (first xs)
(prod (rest xs)))))
package { import flash.display.Sprite;  public class SumAndProduct extends Sprite {
public function SumAndProduct()
var arr:Array = [1, 2, 3, 4, 5];
var sum:int = 0;
var prod:int = 1; 
for (var i:int = 0; i & arr.length; i++)
sum += arr[i];
prod *= arr[i];
} 
trace(&Sum: & + sum); // 15
trace(&Product: & + prod); // 120
} }}
type Int_Array is array(Integer range &&) of I array : Int_Array := (1,2,3,4,5,6,7,8,9,10);Sum : Integer := 0;for I in array'range loop
Sum := Sum + array(I);end loop;
Define the product function
function Product(Item : Int_Array) return Integer is
Prod : Integer := 1;begin
for I in Item'range loop
Prod := Prod * Item(I);
return Pend P
This function will raise the predefined exception Constraint_Error if the product overflows the values represented by type Integer
voidcompute(integer &s, integer &p, list l){ 
i = l_length(l);
while (i) {
s += l_q_integer(l, i);
p *= l_q_integer(l, i);
}} integermain(void){
integer sum, 
compute(sum, product, l_effect(2, 3, 5, 7, 11, 13, 17, 19)); 
o_integer(sum);
o_newline();
o_integer(product);
o_newline(); 
return 0;}
main:(
INT default upb := 3;
MODE INTARRAY = [default upb]INT; 
INTARRAY array = (1,2,3,4,5,6,7,8,9,10);
INT sum := 0;
FOR i FROM LWB array TO UPB array DO
sum +:= array[i]
# Define the product function #
PROC int product = (INTARRAY item)INT:
INT prod :=1;
FOR i FROM LWB item TO UPB item DO
prod *:= item[i]
) # int product # ;
printf(($& Sum: &g(0)$,sum,$&, Product:&g(0)&;&l$,int product(array))))
Sum: 55, Product:3628800;
begin 
 % computes the sum and product of intArray
 % the results are returned in sum and product
 % the bounds of the array must be specified in lb and ub
procedure sumAndProduct( integer array
intArray ( * )
 ; integer value
 ; integer result sum, product
begin 
 := 0;
product := 1; 
for i := lb until ub
sum + intArray( i );
product := product * intArray( i );
end for_i ; 
end sumAndProduct ; 
 % test the sumAndProduct procedure
begin 
integer array v
( 1 :: 10 );
integer sum, 
for i := 1 until 10 do v( i ) := 
sumAndProduct( v, 1, 10, sum, product );
write( sum, product );
Works with:
1 2 3 4 5  
list15 
prod list120
set array to {1, 2, 3, 4, 5}set sum to 0set product to 1repeat with i in array
set sum to sum + i
set product to product * iend repeat
numbers = 1,2,3,4,5product := 1, parse, numbers, `,{sum += product *= }, sum = %sum%`nproduct = %product%
For array input, it is easiest to "deserialize" it from a string with the split() function.
$ 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 1055 $ 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 103628800
main: { [2 3 5 7 11 13] sp } sum!
 : { &- 0 -& { + } eachar }product!: { &- 1 -& { * } eachar } sp!:
sum %d cr &&
product %d cr && } Result:4130030
Perhaps better Babel:
{ [2 3 5 7 11 13]
ar2ls dup cp
&- sum_stack -&
prod_stack
 %d cr &&
 %d cr && } sum_stack:
{ depth 1 & }
do_while } nest } prod_stack:
{ depth 1 & }
do_while } nest }
The nest operator creates a kind of argument-passing context -
it saves whatever is on Top-of-Stack (TOS), saves the old stack,
clears the stack and places the saved TOS on the new, cleared stack.
This permits a section to monopolize the stack. At the end of the nest
context, whatever is on TOS will be "passed back" to the original stack
which will be restored.
The depth operator returns the current depth of the stack.
Works with:
dim array(5) as integer = { 1, 2, 3, 4, 5 } dim sum as integer = 0dim prod as integer = 1for index as integer = lbound(array) to ubound(array)
sum += array(index)
prod *= array(index)next
10 N = 5 20 S = 0:P = 1: DATA 1,2,3,4,5 30 N = N - 1: DIM A(N) 40
FOR I = 0 TO N 50
READ A(I): NEXT 60
FOR I = 0 TO N 70 S = S + A(I):P = P * A(I) 80
PRINT &SUM=&S,&PRODUCT=&P
DIM array%(5)
array%() = 1, 2, 3, 4, 5, 6 
PRINT &Sum of array elements = & ; SUM(array%()) 
product% = 1
FOR I% = 0 TO DIM(array%(),1)
product% *= array%(I%)
PRINT &Product of array elements = & ; product%
a[0] = 3.0a[1] = 1a[2] = 4.0a[3] = 1.0a[4] = 5a[5] = 9.00n = 6p = 1for (i = 0; i & i++) {
p *= a[i]}&Sum: &; s&Product: &; p
Works with:
The program first reads the number of elements in the array, then the elements themselves (each number on a separate line) and calculates their sum.
0 &&: #v_ $. @
&1- \ & + \v
( ( sumprod
sum prod num
 !arg
( #%?num ?
& !num+!sum:?sum
& !num*!prod:?prod
| (!sum.!prod)
)& out$sumprod$(2 3 5 7 11 13 17 19));
77.9699690
/* using pointer arithmetic (because we can, I guess) */int arg[] = { 1,2,3,4,5 };int arg_length = sizeof(arg)/sizeof(arg[0]);int *end = arg+arg_length;int sum = 0, prod = 1;int *p; for (p = arg; p!=end; ++p) {
sum += *p;
prod *= *p;}
#include &numeric&#include &functional& int arg[] = { 1, 2, 3, 4, 5 };int sum
= std::accumulate(arg, arg+5, 0, std::plus&int&());// or just// std::accumulate(arg, arg + 5, 0);// since plus() is the default functor for accumulateint prod = std::accumulate(arg, arg+5, 1, std::multiplies&int&());
Template alternative:
// this would be more elegant using STL collectionstemplate &typename T& T sum (const T *array, const unsigned n){
T accum = 0;
for (unsigned i=0; i&n; i++)
accum += array[i];
return accum;}template &typename T& T prod (const T *array, const unsigned n){
T accum = 1;
for (unsigned i=0; i&n; i++)
accum *= array[i];
return accum;} #include &iostream&using std::cout;using std::endl; int main (){
int aint[] = {1, 2, 3};
cout && sum(aint,3) && & & && prod(aint, 3) && endl;
float aflo[] = {1.1, 2.02, 3.003, 4.0004};
cout && sum(aflo,4) && & & && prod(aflo,4) && endl;
return 0;}
int sum = 0, prod = 1;int[] arg = { 1, 2, 3, 4, 5 };foreach (int value in arg) {
sum += value;
prod *= value;}
Works with:
int[] arg = { 1, 2, 3, 4, 5 };int sum = arg.Sum();int prod = arg.Aggregate((runningProduct, nextFactor) =& runningProduct * nextFactor);
Sum and Product of Numbers as a Piece of Cake. This recipe sums N given numbers. Ingredients.1 N0 sum1 product1 number Method.Put sum into 1st mixing bowl.Put product into 2nd mixing bowl.Take N from refrigerator.Chop N.Take number from refrigerator.Add number into 1st mixing bowl.Combine number into 2nd mixing bowl.Chop N until choped.Pour contents of 2nd mixing bowl into the baking dish.Pour contents of 1st mixing bowl into the baking dish. Serves 1.
array = {1, 2, 3, 4, 5}Sum = sum [x \\ x &-: array]Prod = foldl (*) 1 [x \\ x &-: array]
(defn sum [vals] (reduce + vals)) (defn product [vals] (reduce * vals))
IDENTIFICATION DIVISION.
PROGRAM-ID. array-sum-and-product. 
DATA DIVISION.
WORKING-STORAGE SECTION.
Array-Size
array-area
PIC 99 OCCURS Array-Size TIMES. 
PIC 9(8).
array-product
PIC 9(10) VALUE 1. 
PIC 99. 
PROCEDURE DIVISION.
PERFORM VARYING i FROM 1 BY 1 UNTIL Array-Size & i
ADD array (i) TO array-sum
MULTIPLY array (i) BY array-product
END-PERFORM 
DISPLAY &Sum:
& array-sum
DISPLAY &Product: & array-product 
 sum = (array) -&
array.reduce (x, y) -& x + y product = (array) -&
array.reduce (x, y) -& x * y 
Sum of an Array,
&cfset Variables.myArray = [1,2,3,4,5,6,7,8,9,10]&&cfoutput&#ArraySum(Variables.myArray)#&/cfoutput&
Product of an Array,
&cfset Variables.myArray = [1,2,3,4,5,6,7,8,9,10]&&cfset Variables.Product = 1&&cfloop array=&#Variables.myArray#& index=&i&& &cfset Variables.Product *= i&&/cfloop&&cfoutput&#Variables.Product#&/cfoutput&
(let ((data #(1 2 3 4 5)))
; the array
(values (reduce #'+ data)
(reduce #'* data)))
The loop macro also has support for sums.
(loop for i in '(1 2 3 4 5) sum i)
import std.stdio; void main() {
immutable array = [1, 2, 3, 4, 5]; 
int sum = 0;
int prod = 1; 
foreach (x; array) {
prod *= x;
} 
writeln(&Sum: &, sum);
writeln(&Product: &, prod);}
Product: 120
Compute sum and product of array in one pass (same output):
import std.stdio, std.algorithm, std.typecons; void main() {
immutable array = [1, 2, 3, 4, 5]; 
// Results are stored in a 2-tuple
immutable r = reduce!(q{a + b}, q{a * b})(tuple(0, 1), array); 
writeln(&Sum: &, r[0]);
writeln(&Product: &, r[1]);}
program SumAndProductOfArray; {$APPTYPE CONSOLE} var
i: integer;
lIntArray: array [1 .. 5] of integer = (1, 2, 3, 4, 5);
lSum: integer = 0;
lProduct: integer = 1;begin
for i := 1 to length(lIntArray) do
Inc(lSum, lIntArray[i]);
lProduct := lProduct * lIntArray[i]
end; 
Write('Sum: ');
Writeln(lSum);
Write('Product: ');
Writeln(lProduct);end.
pragma.enable(&accumulator&) 0
[1,2,3,4,5] { _ + x } 1
[1,2,3,4,5] { _ * x }
Works with:
version version 21.5.21
(setq array [1 2 3 4 5])(eval (concatenate 'list '(+) array))(eval (concatenate 'list '(*) array))
(setq array '(1 2 3 4 5))(apply '+ array)(apply '* array)
(setq array [1 2 3 4 5])(apply '+ (append array nil))(apply '* (append array nil))
 class APPLICATION create make feature {}  make
[]
create test.make_empty
test := &&5, 1, 9, 7&&
io.put_string (&Sum: & + sum (test).out)
io.new_line
io.put_string (&Product: & + product (test).out)
end  sum (ar:
[]):
-- Sum of the items of the array 'ar'.
ar.lower |..| ar.upper as c
Result := Result + ar [c.item]
end  product (ar:
[]):
-- Product of the items of the array 'ar'.
Result := 1
ar.lower |..| ar.upper as c
Result := Result * ar [c.item]
end end 
Sum of the elements of the array: 30
Product of the elements of the array: 3840
When an accumulator is omitted, the first element of the collection is used as the initial value of acc.
iex(26)& Enum.reduce([1,2,3,4,5], 0, fn x,acc -& x+acc end)15iex(27)& Enum.reduce([1,2,3,4,5], 1, fn x,acc -& x*acc end)120iex(28)& Enum.reduce([1,2,3,4,5], fn x,acc -& x+acc end)15iex(29)& Enum.reduce([1,2,3,4,5], fn x,acc -& x*acc end)120iex(30)& Enum.reduce([], 0, fn x,acc -& x+acc end)0iex(31)& Enum.reduce([], 1, fn x,acc -& x*acc end)1iex(32)& Enum.reduce([], fn x,acc -& x+acc end)** (Enum.EmptyError) empty error
(elixir) lib/enum.ex:1287: Enum.reduce/2iex(32)& Enum.reduce([], fn x,acc -& x*acc end)** (Enum.EmptyError) empty error
(elixir) lib/enum.ex:1287: Enum.reduce/2
The function with sum
Enum.sum([1,2,3,4,5])
Using the standard libraries:
% create the list:L = :seq(1, 10). % and compute its sum:S = :sum(L).P = :foldl(fun (X, P) -& X * P end, 1, L).
To compute sum and products in one pass:
 {Prod,Sum} = :foldl(fun (X, {P,S}) -& {P*X,S+X} end, {1,0}, :seq(1,10)).
Or defining our own versions:
-module(list_sum).-export([sum_rec/1, sum_tail/1]). % recursive definition:sum_rec([]) -&
0;sum_rec([Head|Tail]) -&
Head + sum_rec(Tail). % tail-recursive definition:sum_tail(L) -&
sum_tail(L, 0).sum_tail([], Acc) -&
Acc;sum_tail([Head|Tail], Acc) -&
sum_tail(Tail, Head + Acc).
sequence arrayinteger sum,prod array = { 1, 2, 3, 4, 5 } sum = 0prod = 1for i = 1 to length(array) do
sum += array[i]
prod *= array[i]end for printf(1,&sum is %d\n&,sum)printf(1,&prod is %d\n&,prod)
prod is 120
 let numbers = [| 1..10 |]let sum = numbers |& .sumlet product = numbers |& .fold (*) 1 
1 5 1 &range& [ sum . ] [ product . ] bi
15 120{ 1 2 3 4 } [ sum ] [ product ] bi
sum and product are defined in the sequences vocabulary:
: sum ( seq -- n ) 0 [ + ] reduce ;: product ( seq -- n ) 1 [ * ] reduce ;
Strictly speaking, there are no arrays in FALSE. However, a number of elements on the stack could be considered an array. The implementation below assumes the length of the array on top of the stack, and the actual items below it. Note that this implementation does remove the "array" from the stack, so in case the original values need to be retained, a copy should be provided before executing this logic.
1 2 3 4 5 {input &array&}5
{length of input}0s:
{product} [$0=~][1-\$s;+s:p;*p:]#% &Sum: &s;.&Product: &p;.
Product: 120
 class Main{
public static Void main ()
Int[] array := (1..20).toList 
// you can use a loop
Int sum := 0
array.each |Int n| { sum += n }
echo (&Sum of array is : $sum&) 
Int product := 1
array.each |Int n| { product *= n }
echo (&Product of array is : $product&) 
// or use 'reduce'
// 'reduce' takes a function,
the first argument is the accumulated value
and the second is the next item in the list
sum = array.reduce(0) |Obj r, Int v -& Obj|
return (Int)r + v
echo (&Sum of array : $sum&) 
product = array.reduce(1) |Obj r, Int v -& Obj|
return (Int)r * v
echo (&Product of array : $product&)
: third ( a b c -- a b c a ) 2 pick ;: reduce ( xt n addr cnt -- n' ) \ where xt ( a b -- n )
cells bounds do i @ third execute
cell +loop nip ; create a 1 , 2 , 3 , 4 , 5 , ' + 0 a 5 reduce .
\ 15' * 1 a 5 reduce .
In ISO Fortran 90 and later, use SUM and PRODUCT intrinsics:
integer, dimension(10) :: a = (/ (i, i=1, 10) /)integer :: sresult, presult sresult = sum(a);presult = product(a);
 a = [1,2,3,5,7]sum[a]product[a] 
v := [1 .. 8]; Sum(v);# 36 Product(v);# 40320 # You can sum or multiply the result of a function Sum(v, n -& n^2);# 204 Product(v, n -& 1/n);# 1/40320
package main import &fmt& func main() {
sum, prod := 0, 1
for _, x := range []int{1,2,5} {
fmt.Println(sum, prod)}
Groovy adds a "sum()" method for collections, but not a "product()" method:
[1,2,3,4,5].sum()
However, for general purpose "reduction" or "folding" operations, Groovy does provide an "inject()" method for collections similar to "inject" in Ruby.
[1,2,3,4,5].(0) { sum, val -& sum + val }[1,2,3,4,5].(1) { prod, val -& prod * val }
You can also combine these operations:
([1,2,3,4,5].([sum: 0, product: 1]) { result, value -&
[sum: result.sum + value, product: result.product * value]})
Works with:
Works with:
10 REM Create an array with some test
A(5)30 FOR I = 1 TO 5:
A(I): NEXT I40
1, 2, 3, 4, 550 REM Find the sum of elements in the array60 S = 065 P = 170 FOR I = 1 TO 572 S = SUM + A(I)75 P = P * A(I)77 NEXT I80
&The sum is &; S;90
& and the product is &; P
For lists, sum and product are already defined in the Prelude:
values = [1..10] s =
-- the easy wayp =
values s' = foldl (+) 0 values
-- the hard wayp' =
(*) 1 values
To do the same for an array, just convert it lazily to a list:
import Data.Array values = listArray (1,10) [1..10] s =
. elems $ valuesp =
. elems $ values
array = $ ! 1, 2, ..., LEN(array) sum = SUM(array) product = 1 ! no built-in product function in HicEstDO i = 1, LEN(array)
product = product * array(i)ENDDO WRITE(ClipBoard, Name) n, sum, product ! n=100; sum=5050; product=9.;
array = [3,6,8]print,total(array)print,product(array)
The program below prints the sum and product of the arguments to the program.
procedure main(arglist)every ( sum := 0 ) +:= !arglistevery ( prod := 1 ) *:= !arglistwrite(&sum := &, sum,&, prod := &,prod)end
Sum And Product is a room. To decide which number is the sum of (N - number) and (M - number) (this is summing): decide on N + M. To decide which number is the product of (N - number) and (M - number) (this is production): decide on N * M. When play begins: let L be {1, 2, 3, 4, 5}; say &List: [L in brace notation], sum = [summing reduction of L], product = [production reduction of L].&; end the story.
=: +/product =: */
For example:
sum 1 3 5 7 9 11 1349
product 1 3 5 7 9 11 13135135 
a=: 3 10 ?@$ 100
NB. random array
a90 47 58 29 22 32 55
5 55 7358 50 40
5 69 46 34 40 46 8429
8 75 97 24 40 21 82 77
NB. on a table, each row is an item to be summed:
sum a177 105 173 131 115 118 110 127 178 166
product a151380 18800 174000 14065 36432 58880 39270 16400 194810 55188 
NB. but we can tell J to sum everything within each row, instead:
sum&1 a466 472 462
product&1 a5.53041e15 9.67411e15 1.93356e15
Works with:
version 1.5+
public class SumProd{ public static void main(final [] args) {
int sum = 0;
int prod = 1;
int[] arg = {1,2,3,4,5};
for (int i : arg)
prod *= i;
} }}
Works with:
version 1.8+
import java.util.Arrays; public class SumProd{ public static void main(final [] args) {
int[] arg = {1,2,3,4,5};
.out.printf(&sum = %d\n&, .stream(arg).sum());
.out.printf(&sum = %d\n&, .stream(arg).reduce(0, (a, b) -& a + b));
.out.printf(&product = %d\n&, .stream(arg).reduce(1, (a, b) -& a * b)); }}
product = 120
var array = [1, 2, 3, 4, 5],
i;for (i = 0; i & array.length; i += 1) {
sum += array[i];
prod *= array[i];}alert(sum + ' ' + prod);
Works with:
version 1.8
Where supported, the reduce method can also be used:
var array = [1, 2, 3, 4, 5],
sum = array.reduce(function (a, b) {
return a + b;
}, 0),
prod = array.reduce(function (a, b) {
return a * b;
}, 1);alert(sum + ' ' + prod);
The builtin filter, add/0, computes the sum of an array:
[4,6,8] | add# =& 18
[range(2;5) * 2] | add# =& 18
An efficient companion filter for computing the product of the items in an array can be defined as follows:
def prod: reduce .[] as $i (1; . * $i);
[4,6,8] | prod # =& 192
[range(1;11)] | prod# =&3628800
julia& sum([4,6,8])18 julia& +((1:10)...)55 julia +([1,2,3]...)6 julia& prod([4,6,8])192
4 iota 1 + dup '+ reduce'* reduce
local(x = array(1,2,3,4,5,6,7,8,9,10))// sum of array elements'Sum: 'with n in #xsum #n'\r'// product of arrray elements'Product: 'local(product = 1)with n in #x do =& { #product *= #n }#product
Product: 3628800
Dim array(19) For i = 0 To 19
array(i) = Int(Rnd(1) * 20)Next i 'product must first equal one or you will get 0 as the productproduct = 1For i = 0 To 19
sum = (sum + array(i))
product = (product * array(i))next i Print &Sum is & + str$(sum)Print &Product is & + str$(product)
print apply &sum arraytolist {1 2 3 4 5}print apply &product arraytolist {1 2 3 4 5}
 function sumf(a, ...) return a and a + sumf(...) or 0 endfunction sumt(t) return sumf(unpack(t)) endfunction prodf(a, ...) return a and a * prodf(...) or 1 endfunction prodt(t) return prodf(unpack(t)) end print(sumt{1, 2, 3, 4, 5})print(prodt{1, 2, 3, 4, 5})
 function table.sum(arr, length)
--same as if && then && else &&
return length == 1 and arr[1] or arr[length] + table.sum(arr, length -1)end function table.product(arr, length)
return length == 1 and arr[1] or arr[length] * table.sum(arr, length -1)end t = {1,2,3}print(table.sum(t,#t))print(table.product(t,3)) 
prints a running sum and product of sequence 1,2,3...
[%sum,product%] where
x = 1 fby x + 1;
sum = 0 fby sum +
product = 1 fby product * x end
Mathematica provides many ways of doing the sum of an array (any kind of numbers or symbols):
a = {1, 2, 3, 4, 5}Plus @@ aApply[Plus, a]Total[a]Total@aa // TotalSum[a[[i]], {i, 1, Length[a]}]Sum[i, {i, a}]
all give 15. For product we also have a couple of choices:
a = {1, 2, 3, 4, 5}Times @@ aApply[Times, a]Product[a[[i]], {i, 1, Length[a]}]Product[i, {i, a}]
all give 120.
These two function are built into MATLAB as the "sum(array)" and "prod(array)" functions.
Sample Usage:
&& array = [1 2 3;4 5 6;7 8 9] array = 
9 && (array,1)  = 
18 && (array,2)  = 
24 && (array,1)  = 
162 && (array,2)  = 
lreduce(&+&, [1, 2, 3, 4, 5, 6, 7, 8]);36 lreduce(&*&, [1, 2, 3, 4, 5, 6, 7, 8]);40320
arr = #(1, 2, 3, 4, 5)sum = 0for i in arr do sum += iproduct = 1for i in arr do product *= i
^ 1 ПE + П0 КИП0 x#0 18 ^ ИПD+ ПD &-& ИПE * ПE БП 05 С/П
Instruction: РX - array length, Р1:РC - array, РD and РE - sum and product of an array.
MODULE Sumprod EXPORTS M FROM IO IMPORT PFROM Fmt IMPORT I VAR a := ARRAY [1..5] OF INTEGER {1, 2, 3, 4, 5};VAR sum: INTEGER := 0;VAR prod: INTEGER := 1; BEGIN
FOR i := FIRST(a) TO LAST(a) DO
INC(sum, a[i]);
prod := prod * a[i];
Put(&Sum of array: & & Int(sum) & &\n&);
Put(&Product of array: & & Int(prod) & &\n&);END Sumprod.
Sum of array: 15
Product of array: 120
 SUMPROD(A) ;Compute the sum and product of the numbers in the array A NEW SUM,PROD,POS ;SUM is the running sum,  ;PROD is the running product, ;POS is the position within the array A SET SUM=0,PROD=1,POS=&& FOR
SET POS=$ORDER(A(POS)) Q:POS=&&
SET SUM=SUM+A(POS),PROD=PROD*A(POS) WRITE !,&The sum of the array is &_SUM WRITE !,&The product of the array is &_PROD KILL SUM,PROD,POS QUIT
USER&SET C(-1)=2,C(&A&)=3,C(42)=1,C(0)=7
USER&D SUMPROD^ROSETTA(.C)
The sum of the array is 13
The product of the array is 42
Note - the string "A" converts to 0 when doing mathematical operations.
USER&SET C(-1)=2,C(&A&)=&3H&,C(42)=.1,C(0)=7.0,C(&B&)=&A&
USER&D SUMPROD^ROSETTA(.C)
The sum of the array is 12.1
The product of the array is 0
As mentioned for some of the other functional languages, it seems more natural to work with lists in Nemerle, but as the task specifies working on an array, this solution will work on either.
using Susing System.Cusing System.Collections.Gusing Nemerle.C module SumProd{
Sum[T] (nums : T) : int
where T : IEnumerable[int]
nums.FoldLeft(0, _+_)
Product[T] (nums : T) : int
where T : IEnumerable[int]
nums.FoldLeft(1, _*_)
Main() : void
def arr = array[1, 2, 3, 4, 5];
def lis = [1, 2, 3, 4, 5]; 
def suml = Sum(lis);
def proda = Product(arr); 
WriteLine(&Sum is: {0}\tProduct is: {1}&, suml, proda);
/* NetRexx */ options replace format comments java crossref savelog symbols binary harry = [long 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] sum = long 0product = long 1entries = Rexx '' loop n_ = int 0 to harry.length - 1
nxt = harry[n_]
entries = entries nxt
sum = sum + nxt
product = product * nxt
end n_ entries = entries.strip say 'Sum and product of' entries.changestr(' ', ',')':'say '
Sum:' sumsay ' Product:' product return 
Sum and product of 1,2,3,4,5,6,7,8,9,10:
Product: 3628800
( a '(1 2 3 4 5))( + a)( * a)
Nial being an array language, what applies to individual elements are extended to cover array operations by default strand notation
+ 1 2 3= 6* 1 2 3= 6
array notation
grouped notation
(* 1 2 3)= 6* (1 2 3)= 6
(All these notations are equivalent)
var xs = @[1,2,3,4,5,6] var sum, product: int product = 1 for x in xs:
product *= x
Or functionally:
import sequtils let
xs = @[1,2,3,4,5,6]
sum = xs.foldl(a + b)
product = xs.foldl(a * b)
 sum := 0;prod := 1;arg := [1, 2, 3, 4, 5];each(i : arg) {
sum += arg[i];
prod *= arg[i];}; 
Works with:
version 4.0.1 (apple)
- (float) sum:( *)array{
int i, sum, sum = 0; value = 0;  for (i = 0; i & [array count]; i++) {
value = [[array objectAtIndex: i] intValue];
sum += }  return}
- (float) prod:( *)array{
int i, prod, prod = 0; value = 0;  for (i = 0; i & [array count]; i++) {
value = [[array objectAtIndex: i] intValue];
prod *= }  return}
(* ints *)let a = [| 1; 2; 3; 4; 5 |];;.fold_left (+) 0 a;;.fold_left ( * ) 1 a;;(* floats *)let a = [| 1.0; 2.0; 3.0; 4.0; 5.0 |];;.fold_left (+.) 0.0 a;;.fold_left ( *.) 1.0 a;;
(* ints *)let x = [1; 2; 3; 4; 5];;.fold_left (+) 0 x;;.fold_left ( * ) 1 x;;(* floats *)let x = [1.0; 2.0; 3.0; 4.0; 5.0];;.fold_left (+.) 0.0 x;;.fold_left ( *.) 1.0 x;;
a = [ 1, 2, 3, 4, 5, 6 ];b = [ 10, 20, 30, 40, 50, 60 ];vsum = a + b;vprod = a .* b;
[1, 2, 3, 4, 5 ] sum println[1, 3, 5, 7, 9 ] prod println
Translation of:
a=.my_array~new(20)do i=1 To 20
a[i]=i
Ends=a~makestring((LINE),',')Say sSay '
sum='a~sumSay 'product='a~prod::class my_array subclass array::method sumsum=0Do i=1 To self~dimension(1)
sum+=self[i]
EndReturn sum::method prodNumeric Digits 30prod=1Do i=1 To self~dimension(1)
prod*=self[i]
EndReturn prod
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
product=6640000
Calculations like this are typically done on lists, not on arrays:
Xs = [1 2 3 4 5]
Sum = {FoldL Xs Number.'+' 0}
Product = {FoldL Xs Number.'*' 1}in
{Show Sum}
{Show Product}
If you are actually working with arrays, a more imperative approach seems natural:
Arr = {Array.new 1 3 0}
Sum = {NewCell 0}in
Arr.1 := 1
Arr.2 := 2
Arr.3 := 3 
for I in {Array.low Arr}..{Array.high Arr} do
Sum := @Sum + Arr.I
{Show @Sum}
vecsum(v)={
sum(i=1,#v,v[i])};vecprod(v)={
prod(i=1,#v,v[i])};
my @list = ( 1, 2, 3 ); my ( $sum, $prod ) = ( 0, 1 );$sum
+= $_ foreach @list;$prod *= $_ foreach @list;
Or using the
use List::Util qw/sum0 product/;my @list = (1..9); say &Sum: &, sum0(@list);
# sum0 returns 0 for an empty listsay &Product: &, product(@list);
Product: 362880
my @ary = 1, 5, 10, 100;say 'Sum: ',
[+] @ary;say 'Product: ', [*] @ary;
$array = (1,2,3,4,5,6,7,8,9);echo ($array);echo ($array);
(let Data (1 2 3 4 5)
(apply + Data)
(apply * Data) ) )
(15 . 120)
declare A(10) fixed binary static initial
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); put skip list (sum(A));put skip list (prod(A));
Simple loop:
lvars i, sum = 0, prod = 1, ar = {1 2 3 4 5 6 7 8 9};for i from 1 to length(ar) do
ar(i) + sum -&
ar(i) * prod -&
One can alternatively use second order iterator:
lvars sum = 0, prod = 1, ar = {1 2 3 4 5 6 7 8 9};appdata(ar, procedure(x); x + sum -& endprocedure);appdata(ar, procedure(x); x * prod -& endprocedure);
The Measure-Object cmdlet already knows how to compute a sum:
function Get-Sum ($a) {
return ($a | Measure-Object -Sum).Sum}
But not how to compute a product:
function Get-Product ($a) {
if ($a.Length -eq 0) {
} else {
foreach ($x in $a) {
}}
One could also let PowerShell do all the work by simply creating an expression to evaluate:
Works with:
function Get-Product ($a) {
if ($a.Length -eq 0) {
$s = $a -join '*'
return (Invoke-Expression $s)}
Even nicer, however, is a function which computes both at once and returns a custom object with appropriate properties:
function Get-SumAndProduct ($a) {
if ($a.Length -eq 0) {
} else {
foreach ($x in $a) {
$sum += $x
$prod *= $x
$ret = New-Object PSObject
$ret | Add-Member NoteProperty Sum $sum
$ret | Add-Member NoteProperty Product $prod
return $ret}
PS& Get-SumAndProduct 5,9,7,2,3,8,4
Sum Product
--- -------
sum([],0).sum([H|T],X) :- sum(T,Y), X
H + Y.product([],1).product([H|T],X) :- product(T,Y), X
:- sum([1,2,3,4,5,6,7,8,9],X).
:- product([1,2,3,4,5],X).
Using fold
 add(A,B,R):-
A + B. mul(A,B,R):-
A * B. % define fold now.fold([], Act, Init, Init). fold(Lst, Act, Init, Res):-
head(Lst,Hd),
tail(Lst,Tl),
apply(Act,[Init, Hd, Ra]),
fold(Tl, Act, Ra, Res). sumproduct(Lst, Sum, Prod):-
fold(Lst,mul,1, Prod),
fold(Lst,add,0, Sum). ?- sumproduct([1,2,3,4],Sum,Prod).Sum = 10,Prod = 24 .  
 /sumandproduct{/x exch def/sum 0 def/prod 0 def/i 0 defx length 0 eq{}{/prod prod 1 add defx length{/sum sum x i get add def/prod prod x i get mul def/i i 1 add def}repeat}ifelsesum ==prod ==}def 
 % sum[1 1 1 1 1] 0 {add} fold% product[1 1 1 1 1] 1 {mul} fold  
Dim MyArray(9)Define a, sum=0, prod=1 For a = 0 To ArraySize(MyArray())
; Create a list of some random numbers
MyArray(a) = 1 + Random(9)
; Insert a number [1...10] in current elementNext For a = 0 To ArraySize(MyArray())
; Calculate Sum and Product of this Array
+ MyArray(a)
prod * MyArray(a)Next Debug &The sum is & + Str(sum)
; Present the resultsDebug &Product is & + Str(prod)
Works with:
version 2.5
numbers = [1, 2, 3]total = sum(numbers) product = 1for i in numbers:
product *= i
Or functionally (faster but perhaps less clear):
Works with:
version 2.5
from operator import mul, addsum = reduce(add, numbers) # note: this version doesn't work with empty listssum = reduce(add, numbers, 0)product = reduce(mul, numbers) # note: this version doesn't work with empty listsproduct = reduce(mul, numbers, 1)
from numpy import r_numbers = r_[1:4]total = numbers.sum()product = numbers.prod()
If you are summing floats in Python 2.6+, you should use math.fsum() to avoid loss of precision:
Works with:
version 2.6, 3.x
import mathtotal = math.fsum(floats)
total &- sum(1:5)product &- prod(1:5)
 #lang racket (for/sum ([x #(3 1 4 1 5 9)]) x)(for/product ([x #(3 1 4 1 5 9)]) x) 
0 [ 1 2 3 ] each +1 [ 1 2 3 ] each *
Title: &Sum and Product&
Author: oofoe
URL: http://rosettacode.org/wiki/Sum_and_product_of_array] ; Simple: sum: func [a [block!] /local x] [x: 0
forall a [x: x + a/1]
x] product: func [a [block!] /local x] [x: 1
forall a [x: x * a/1]
x] ; Way too fancy: redux: func [ &Applies an operation across an array to produce a reduced value.& a [block!] &Array to operate on.& op [word!] &Operation to perform.& /init x
&Initial value (default 0).&][if not init [x: 0]
forall a [x: do compose [x (op) (a/1)]]
x] rsum: func [a [block!]][redux a '+] rproduct: func [a [block!]][redux/init a '* 1] ; Tests: assert: func [code][print [either do code [&
ok&][&FAIL&]
mold code]] print &Simple dedicated functions:&assert [55
= sum [1 2 3 4 5 6 7 8 9 10]]assert [3628800 = product [1 2 3 4 5 6 7 8 9 10]] print [crlf &Fancy reducing function:&]assert [55
= rsum [1 2 3 4 5 6 7 8 9 10]]assert [3628800 = rproduct [1 2 3 4 5 6 7 8 9 10]]
Simple dedicated functions:
ok [55 = sum [1 2 3 4 5 6 7 8 9 10]]
ok [3628800 = product [1 2 3 4 5 6 7 8 9 10]]
Fancy reducing function:
ok [55 = rsum [1 2 3 4 5 6 7 8 9 10]]
ok [3628800 = rproduct [1 2 3 4 5 6 7 8 9 10]]
/*REXX program adds and multiplies
elements of a (populated)
@. */numeric digits 200
/*200 decimal digit #s
(default is 9).*/parse arg N .;
/*Not specified?
Then use the default.*/ 
/*build array of
elements (or 20?).*/
/*set 1st to 1, 3rd to 3, 8th to 8 ··· */
/*j*/sum=0
/*initialize
(variable) to zero. */prod=1
/*initialize
PROD (variable) to unity.*/
/*add the element to the running total.*/
prod = prod * @.k
/*multiply element to running product. */
same as N factorial.*/ say '
& elements for the
array is: &
sumsay ' product of '
& elements for the
array is: &
/*stick a fork in it,
we're all done. */
output using the default input of:  
elements for the
product of
elements for the
arr = [1,2,3,4,5]
# or ary = *1..5, or ary = (1..5).to_ap sum = arr.inject(0) { |sum, item| sum + item }# =& 15p product = arr.inject(1) { |prod, element| prod * element }# =& 120
Works with:
version 1.8.7
arr = [1,2,3,4,5]p sum = arr.inject(0, :+)
#=& 15p product = arr.inject(1, :*)
#=& 120 # If you do not explicitly specify an initial value for memo,# then the first element of collection is used as the initial value of memo.p sum = arr.inject(:+)
#=& 15p product = arr.inject(:*)
Note: When the Array is empty, the initial value returns. However, nil returns if not giving an initial value.
arr = []p arr.inject(0, :+)
#=& 0p arr.inject(1, :*)
#=& 1p arr.inject(:+)
#=& nilp arr.inject(:*)
Enumerable#reduce is the alias of Enumerable#inject.
dim array(100)for i = 1 To 100
array(i) = rnd(0) * 100next i product = 1for i = 0 To 19
= (sum + array(i))
product = (product * array(i))next i Print &
Sum is &;sumPrint &Product is &;product
fn main() {
let arr = [1i32, 2, 3, 4, 5, 6, 7, 8, 9]; 
// using fold
let sum = arr.iter().fold(0, |sum, &b| a + b);
let product = arr.iter().fold(1, |prod, &b| a * b);
println!(&the sum is {} and the product is {}&, sum, product); 
// or using sum and product
// these are NOT YET STABLE
let sum2 = arr.iter().sum();
let product2 = arr.iter().product();
println!(&the sum is {} and the product is {}&, sum2, product2);
data _null_;
array a{*} a1-a100;
do i=1 to 100;
a{i}=i*i;
b=sum(of a{*});
class MAIN is
a :ARRAY{INT} := |10, 5, 5, 20, 60, 100|;
sum, prod :INT;
loop sum := sum + a.elt!;
prod := 1;
loop prod := prod * a.elt!;
#OUT + sum + & & + prod + &\n&;
seq = Seq(1, 2, 3, 4, 5) sum = seq.foldLeft(0)(_ + _) product = seq.foldLeft(1)(_ * _)
Or even shorter:
sum = seq.sum product = seq.product
Works with all data types for which a Numeric implicit is available.
(apply + '(1 2 3 4 5))(apply * '(1 2 3 4 5))
A tail-recursive solution, without the n-ary operator "trick". Because Scheme supports tail call optimization, this is as space-efficient as an imperative loop.
(define (reduce f i l)
(if (null? l)
(reduce f (f i (car l)) (cdr l)))) (reduce + 0 '(1 2 3 4 5)) ;; 0 is unit for +(reduce * 1 '(1 2 3 4 5)) ;; 1 is unit for *
const func integer: sumArray (in array integer: valueArray) is func
var integer: sum is 0;
var integer: value is 0;
for value range valueArray do
sum +:= const func integer: prodArray (in array integer: valueArray) is func
var integer: prod is 1;
var integer: value is 0;
for value range valueArray do
Call these functions with:
writeln(sumArray([](1, 2, 3, 4, 5)));
writeln(prodArray([](1, 2, 3, 4, 5)));
numbers := [1 2 3 4 5 6 7 8 9];print(+/ numbers, */ numbers);
=& 45 362880
var ary = &#91;1, 2, 3, 4, 5&#93;;say ary<<+>>;
# =& 15say ary<<*>>;
#(1 2 3 4 5) reduce: [:sum&#160;:number | sum + number]#(1 2 3 4 5) reduce: [:product&#160;:number | product * number]
Shorthand for the above with a macro:
#(1 2 3 4 5) reduce: #+ `er#(1 2 3 4 5) reduce: #* `er
#&#40;1 2 3 4 5&#41; inject: 0 into: &#91;:sum&#160;:number | sum + number&#93;#&#40;1 2 3 4 5&#41; inject: 1 into: &#91;:product&#160;:number | product * number&#93;
Some implementation also provide a fold: message:
#&#40;1 2 3 4 5&#41; fold: &#91;:sum&#160;:number | sum + number&#93;#&#40;1 2 3 4 5&#41; fold: &#91;:product&#160;:number | product * number&#93;
t = table()* read the integer from the std. inputinit_tab
t&x = x + 1& = trim(input)
&#160;:s(init_tab)
product = 1
sum = 0&#160;* counting backwards to 1loop
i = t& x =&#160;?gt(x,1) x - 1& :f(out)
sum = sum + i
product = product * i
&#160;:(loop)out
output = &Sum:
output = &Prod: & productend
(* ints *)val a = Array.fromList [1, 2, 3, 4, 5];Array.foldl op+ 0Array.foldl op* 1(* reals *)val a = Array.fromList [1.0, 2.0, 3.0, 4.0, 5.0];Array.foldl op+ 0.0Array.foldl op* 1.0
(* ints *)val x = [1, 2, 3, 4, 5];foldl op+ 0foldl op* 1(* reals *)val x = [1.0, 2.0, 3.0, 4.0, 5.0];foldl op+ 0.0foldl op* 1.0
spn:1& reduce({ 1, 2, 3, 4, 5 }, 0, function(x, y) { return x + })= 15spn:2& reduce({ 1, 2, 3, 4, 5 }, 1, function(x, y) { return x * })= 120
let a = [1, 2, 3, 4, 5]println(a.reduce(0, +)) // prints 15println(a.reduce(1, *)) // prints 120&#160;println(reduce(a, 0, +)) // prints 15println(reduce(a, 1, *)) // prints 120
set arr &#91;list 3 6 8&#93;set sum &#91;expr &#91;join $arr +&#93;&#93;set prod &#91;expr &#91;join $arr *&#93;&#93;
Works with:
version 8.5
set arr &#91;list 3 6 8&#93;set sum &#91;tcl::mathop::+ &#123;*&#125;$arr&#93;set prod &#91;tcl::mathop::* &#123;*&#125;$arr&#93;
Use the built-in functions sum() and prod().
4 cells is-array foo&#160;212 1 foo array.put51 2 foo array.put12 3 foo array.put91 4 foo array.put&#160;[ ( array size -- sum )
&r 0 r& 0 [ over i swap array.get + ] countedLoop nip ] is sum-array&#160; ( product )reset 1 4 0 [ i foo array.get * ] countedLoop .
[1 2 3 4 5] 0 [+] foldl
[1 2 3 4 5] 1 [*] foldl
&#160;$$ MODE TUSCRIPTlist=&1'2'3'4'5&sum=SUM(list)PRINT &
sum: &,sum&#160;product=1LOOP l=listproduct=product*lENDLOOPPRINT &product: &,product&#160;
product: 120
Works with:
version 3.0
From an internal variable, $IFS delimited:
sum=0prod=1list=&1 2 3&for n in $listdo sum=&$(($sum + $n))&; prod=&$(($prod * $n))&doneecho $sum $prod
From the argument list (ARGV):
sum=0prod=1for ndo sum=&$(($sum + $n))&; prod=&$(($prod * $n))&doneecho $sum $prod
From STDIN, one integer per line:
sum=0prod=1while read ndo sum=&$(($sum + $n))&; prod=&$(($prod * $n))&doneecho $sum $prod
Works with:
version 3.2.0(1)-release (i386-unknown-freebsd6.1)
From variable:
LIST='20 20 2';SUM=0; PROD=1;for i in $LIST; do
SUM=$&#91;$SUM + $i&#93;; PROD=$&#91;$PROD * $i&#93;;done;echo $SUM $PROD
Uses -style process substitution.
Works with:
prod&#40;&#41; &#123;
&#40;read B; res=$1; test -n &$B& && expr $res \* $B || echo $res&#41;&#125;&#160;sum&#40;&#41; &#123;
&#40;read B; res=$1; test -n &$B& && expr $res + $B || echo $res&#41;&#125;&#160;fold&#40;&#41; &#123;
&#40;func=$1; while read a&#160;; do fold $func | $func $a&#160;; done&#41;&#125;&#160;&#160;&#40;echo 3; echo 1; echo 4;echo 1;echo 5;echo 9&#41; |
tee &&#40;fold sum&#41; &&#40;fold prod&#41; & /dev/null
There is a race between fold sum and fold prod, which run in parallel. The program might print sum before product, or print product before sum.
The reduction operator,&#160;:-, takes an associative binary function and a constant for the empty case.
Natural numbers are unsigned and of unlimited size.
#import nat#cast&#160;%nW&#160;sp = ^(sum:-0,product:-1) &62,43,46,40,29,55,51,82,59,92,48,73,93,35,42,25&
(875,0000)
[sp dup 0 [+] fold 'product=' put puts 1 [*] fold 'sum=' put puts].
[1 2 3 4 5] sp=product=15sum=120
&#160;public static void main&#40;&#41;&#123; int sum = 0, product = 1;&#160; int&#91;&#93; array = &#123;1, 2, 3, 4, 5, 6, 7, 8, 9, 10&#125;;&#160; foreach &#40;int number in array&#41;&#123;
sum += number;
product *= number;
&#125;&#125;&#160;
&#160;Function sum_and_product(arr) sum = 0 product = 1 For i = 0 To UBound(arr)
sum = sum + arr(i)
product = product * arr(i) Next WScript.StdOut.Write &Sum: & & sum WScript.StdOut.WriteLine WScript.StdOut.Write &Product: & & product WScript.StdOut.WriteLineEnd Function&#160;myarray = Array(1,2,3,4,5,6)sum_and_product(myarray)&#160;
Product: 720
def (sum_prod nums)
(list (+ @nums) (* @nums))
code CrLf=9, IntOut=11;&#160;func SumProd(A, L);int
S, P, I;[S:= 0;
P:= 1;for I:= 0 to L-1 do [S:= S+A(I);
P:= P*A(I)];IntOut(0, S);
CrLf(0);IntOut(0, P);
CrLf(0);]; \SumSq&#160;SumProd([1,2,3,4,5,6,7,8,9,10], 10)
@sum [1 2 3 4]&#160;; returns 10@prod [1 2 3 4]&#160;; returns 24
XSLT (or XPath rather) has a few built-in functions for reducing from a collection, but product is not among them. Because of referential transparency, one must resort to recursive solutions for general iterative operations upon collections. The following code represents the array by numeric values in &price& elements in the source document.
&xsl:stylesheet version=&1.0& xmlns:xsl=&http://www.w3.org/1999/XSL/Transform&&
&xsl:output method=&text& /&&#160;
&xsl:template name=&sum-prod&&
&xsl:param name=&values& /&
&xsl:param name=&sum&
select=&0& /&
&xsl:param name=&prod& select=&1& /&
&xsl:choose&
&xsl:when test=&not($values)&&
&xsl:text&Sum: &/xsl:text&
&xsl:value-of select=&$sum& /&
&xsl:text&Product: &/xsl:text&
&xsl:value-of select=&$prod& /&
&/xsl:when&
&xsl:otherwise&
&xsl:call-template name=&sum-prod&&
&xsl:with-param name=&values& select=&$values[position() & 1]& /&
&xsl:with-param name=&sum&
select=&$sum
+ $values[1]& /&
&xsl:with-param name=&prod& select=&$prod * $values[1]& /&
&/xsl:call-template&
&/xsl:otherwise&
&/xsl:choose&
&/xsl:template&&#160;
&xsl:template match=&/&&
&xsl:text&Sum (built-in): &/xsl:text&
&xsl:value-of select=&sum(//price)& /&&#160;
&xsl:call-template name=&sum-prod&&
&xsl:with-param name=&values& select=&//price& /&
&/xsl:call-template&
&/xsl:template&&/xsl:stylesheet&
Translation of:
fcn sum(vals){vals.reduce('+,0)}fcn product(vals){vals.reduce('*,1)}
sum(T(1,2,3,4))
product(T(1,2,3,4)) //--&24

我要回帖

更多关于 error executing tk17 的文章

 

随机推荐