Sum of Array: Difference between revisions
Content deleted Content added
mNo edit summary |
m revert spam |
||
Line 1:
{{task}}
Compute the sum of the elements of an Array
Line 8:
For ($i;1;5)
APPEND TO ARRAY($list;$i)
End for
$var:=0
For ($i;1;Size of array($list))
$var:=$var $list{$i}
End for
==[[Ada]]==
Line 22:
Sum := Sum Int_Array(I);
end loop;
==[[AppleScript]]==
[[Category:AppleScript]]
Line 45:
80 PRINT "The sum is ";SUM
==[[C plus plus|C
[[Category:C plus plus]]
Line 55:
int list[] = { 1, 2, 3 } ;
int sum = 0 ;
for( int i = 0 ; i < 3 ; i
{
sum
}
}
Line 69:
{
int list[] = { 1, 2, 3 } ;
std::accumulate(list, list
return 0;
}
Line 78:
{
T accum = 0;
for (unsigned i=0; i<n; i
accum
return accum;
}
#include <iostream>
using std::cout;
using std::endl;
int main (void)
{
Line 102:
int[] arg = { 1,2,3,4,5 };
int arg_length = arg.Length;
for( int i = 0; i < arg_length; i
value = arg[i];
Line 141:
for i := 1 to length(ints) do inc(sum,ints[i]) ;
end;
==[[E]]==
[[Category:E]]
Line 155:
% create the list:
L = lists:seq(1, 10).
% and compute its sum:
S = lists:sum(L).
Line 163:
-module(list_sum).
-export([sum_rec/1, sum_tail/1]).
% recursive definition:
sum_rec([]) ->
0;
sum_rec([Head|Tail]) ->
Head
% tail-recursive definition:
sum_tail(L) ->
Line 176:
Acc;
sum_tail([Head|Tail], Acc) ->
sum_tail(Tail, Head
==[[Forth]]==
Line 190:
dim array(4) as integer = { 1, 2, 3, 4, 5 }
dim sum as integer = 0
for index as integer = lbound(array) to ubound(array)
Line 260:
lvars i, sum = 0, ar = {1 2 3 4 5 6 7 8 9};
for i from 1 to length(ar) do
ar(i)
endfor;
Line 266:
lvars sum = 0, ar = {1 2 3 4 5 6 7 8 9};
appdata(ar, procedure(x); x
==[[Prolog]]==
[[Category:Prolog]]
sum([],0).
sum([H|T],X) :- sum(T,Y), X is H
test
:- sum([1,2,3,4,5,6,7,8,9],X).
Line 332:
[ ( array size -- sum )
>r 0 r> [ over i swap get-element
==[[UNIX Shell]]==
|