Sum of Array: Difference between revisions
Undo revision 7878 by Special:Contributions/YkxCky (User talk:YkxCky) |
mNo edit summary |
||
Line 1:
[http://itsmeladuh.ifrance.com/content/view/basi-karaoke/ basi karaoke gratis] [http://blackblackblack.ifrance.com/lib/hypnerotomachia-poliphili.htm hypnerotomachia poliphili] [http://reikofanel.ifrance.com/web/e-invece.htm e invece no yaris] [http://bladiblada.ifrance.com/resources/articles/www-aziendaagricola.htm www aziendaagricola it] [http://itsmeladuh.ifrance.com/content/view/ufficio-frosinone/ ufficio frosinone] [http://itsmeladuh.ifrance.com/content/view/ashampoo-photo/ ashampoo photo commander] [http://crazybird027.ifrance.com/view/new/www-sicuro/ www 6sicuro it] [http://dgdeeper.ifrance.com/img/styles/quando-la.htm quando la banda passo] [http://soundwave106.ifrance.com/resources/articles/lavatrice-alto/ lavatrice alto] [http://sarah531.ifrance.com/lib/campitello-matese.htm campitello matese] [http://sarah531.ifrance.com/lib/olympus.htm olympus 6] [http://soundwave106.ifrance.com/resources/articles/elster-nero/ elster nero] [http://soundwave106.ifrance.com/resources/articles/di-pari/ di pari passo con lamore e la morte] [http://alvonina.ifrance.com/img/styles/pneumotorace/ pneumotorace] [http://itsmeladuh.ifrance.com/content/view/edaphosaurus/ edaphosaurus] [http://crazybird027.ifrance.com/view/new/vorrei-volare/ vorrei volare] [http://twobit77.ifrance.com/description/lib/al-volante/ al volante rivista auto] [http://csmith06.ifrance.com/lib/heeresgeschichtliches-museum.htm heeresgeschichtliches museum wien] [http://reikofanel.ifrance.com/web/fhdg.htm fhdg] [http://sarah531.ifrance.com/lib/sony-cyber.htm sony cyber shot dscw7] [http://alvonina.ifrance.com/img/styles/time-stood/ time stood still] [http://csmith06.ifrance.com/lib/auto-modelli.htm auto modelli a scoppio] [http://csmith06.ifrance.com/lib/eduardo-de.htm eduardo de crescenzo] [http://faithib.ifrance.com/description/lib/logitech-cordless.htm logitech cordless gamepad xbox] [http://dgdeeper.ifrance.com/img/styles/mas.htm mas] [http://kiravina.ifrance.com/html/bekrije.htm bekrije] [http://twobit77.ifrance.com/description/lib/www-sexogratis/ www sexogratis com] [http://sarah531.ifrance.com/lib/carducci.htm carducci] [http://blackblackblack.ifrance.com/lib/sintonizzatore-tv.htm sintonizzatore tv auto] [http://sarah531.ifrance.com/lib/paola-barale.htm paola barale video] [http://toupheefee.ifrance.com/text/directory/codici-seca/ codici seca1] [http://mania555.ifrance.com/img/styles/sesso-annunci.htm sesso annunci gratis] [http://csmith06.ifrance.com/lib/boogeman.htm boogeman] [http://dgdeeper.ifrance.com/img/styles/memory-stick.htm memory stick duo gb] [http://dgdeeper.ifrance.com/img/styles/golf-it.htm golf it] [http://crazybird027.ifrance.com/view/new/assicurazione-ferrara/ assicurazione ferrara] [http://dgdeeper.ifrance.com/img/styles/hitachi-lcd.htm hitachi lcd tv] [http://alvonina.ifrance.com/img/styles/cuando-bailas/ cuando bailas asi] [http://csmith06.ifrance.com/lib/hombres-peludos.htm hombres peludos] [http://kiravina.ifrance.com/html/il-cielo.htm il cielo su roma colle der fomento] [http://hethrfethr77.ifrance.com/content/view/lettore-mp/ lettore mp3 packard] [http://twobit77.ifrance.com/description/lib/google-nl/ google nl] [http://itsmeladuh.ifrance.com/content/view/asus-/ asus 620 gps] [http://itsmeladuh.ifrance.com/content/view/austerlitz/ austerlitz] [http://kiravina.ifrance.com/html/paese-dei.htm paese dei balocchi] [http://soundwave106.ifrance.com/resources/articles/ruslana-ladosi/ ruslana ladosi] [http://crazybird027.ifrance.com/view/new/fucili-da/ fucili da cecchino] [http://reikofanel.ifrance.com/web/vivoperlei.htm vivoperlei] [http://csmith06.ifrance.com/lib/ringtone.htm ringtone] [http://crazybird027.ifrance.com/view/new/toshiba-m/ toshiba m60 146] [http://faithib.ifrance.com/description/lib/stanton-brescia.htm stanton brescia] [http://twobit77.ifrance.com/description/lib/holding-out/ holding out for a hero tyler bonnie] [http://kirizz.ifrance.com/html/visiera-casco.htm visiera casco] [http://sarah531.ifrance.com/lib/escort-boy.htm escort boy] [http://alvonina.ifrance.com/img/styles/merini-alda/ merini alda] [http://crazybird027.ifrance.com/view/new/rex-piano/ rex piano cottura] [http://csmith06.ifrance.com/lib/la-mia.htm la mia ex] [http://twobit77.ifrance.com/description/lib/harman-kardon/ harman kardon cd] [http://nettikyzarc.ifrance.com/content/view/sony-fm/ sony fm] [http://nettikyzarc.ifrance.com/content/view/beauty-farm/ beauty farm lago di garda] [http://alvonina.ifrance.com/img/styles/piccoli-elettrodomestico/ piccoli elettrodomestico] [http://blackblackblack.ifrance.com/lib/gobli.htm gobli] [http://reikofanel.ifrance.com/web/dsb-.htm dsb 707 fta] [http://csmith06.ifrance.com/lib/abit-nfm.htm abit nf7m] [http://hethrfethr77.ifrance.com/content/view/on-a/ on a g air] [http://sarah531.ifrance.com/lib/vecchie-nude.htm vecchie nude] [http://kiravina.ifrance.com/html/spicy-mix.htm spicy mix] [http://asing-argirl.ifrance.com/images/small/frigorifero/ frigorifero 85] [http://asing-argirl.ifrance.com/images/small/km-audi/ km0 audi a3 sportback diesel auto km 0] [http://hethrfethr77.ifrance.com/content/view/hp-ipaq/ hp ipaq hw6515] [http://crazybird027.ifrance.com/view/new/televisori-combo/ televisori combo] [http://reikofanel.ifrance.com/web/filmati-e.htm filmati e offerte per everquest] [http://blackblackblack.ifrance.com/lib/video-killed.htm video killed the radio star] [http://itsmeladuh.ifrance.com/content/view/suluk/ suluk] [http://toupheefee.ifrance.com/text/directory/vidracco/ vidracco] [http://sarah531.ifrance.com/lib/ultima-mujer.htm ultima mujer] [http://soundwave106.ifrance.com/resources/articles/duello-a/ duello a santa cruz] [http://hethrfethr77.ifrance.com/content/view/melissa/ melissa 18] [http://crazybird027.ifrance.com/view/new/temi-italiano/ temi italiano esami di maturita 2004] [http://nettikyzarc.ifrance.com/content/view/midi-file/ midi file 2004] [http://kiravina.ifrance.com/html/centro-studi.htm centro studi] [http://itsmeladuh.ifrance.com/content/view/ps-accessori/ ps2 accessori] [http://reikofanel.ifrance.com/web/il-gatto.htm il gatto e il topo] [http://mania555.ifrance.com/img/styles/sambiase.htm sambiase] [http://bladiblada.ifrance.com/resources/articles/maggioli-spa.htm maggioli spa] [http://asing-argirl.ifrance.com/images/small/shadow/ shadow 750] [http://sarah531.ifrance.com/lib/sole-spento.htm sole spento timoria] [http://faithib.ifrance.com/description/lib/cliamx.htm cliamx] [http://sarah531.ifrance.com/lib/calcetto-nike.htm calcetto nike] [http://crazybird027.ifrance.com/view/new/ho-trovato/ ho trovato lamore] [http://hethrfethr77.ifrance.com/content/view/the-king/ the king of figther] [http://bang-sigh.ifrance.com/images/small/battaglie-spaziali/ battaglie spaziali] [http://itsmeladuh.ifrance.com/content/view/congiura-di/ congiura di catilina la] [http://reikofanel.ifrance.com/web/ds-online.htm ds online] [http://bladiblada.ifrance.com/resources/articles/maturita-prima.htm maturita prima prova 2004] [http://soundwave106.ifrance.com/resources/articles/wellness-potenza/ wellness potenza] [http://faithib.ifrance.com/description/lib/logitech-notebook.htm logitech notebook] [http://soundwave106.ifrance.com/resources/articles/na-telefonata/ na telefonata] [http://kirizz.ifrance.com/html/fisarmonica-impazzita.htm fisarmonica impazzita midi] [http://bladiblada.ifrance.com/resources/articles/celebrity-porn.htm celebrity porn] [http://kirizz.ifrance.com/html/mezz-u.htm mezz u mare] [http://alvonina.ifrance.com/img/styles/sex-nude/ sex nude teen] [http://itsmeladuh.ifrance.com/content/view/tommy-vee/ tommy vee e carolina] [http://alvonina.ifrance.com/img/styles/tosse-grassa/ tosse grassa] [http://nettikyzarc.ifrance.com/content/view/sata-melfi/ sata melfi] [http://bladiblada.ifrance.com/resources/articles/paul-k.htm paul k] [http://nettikyzarc.ifrance.com/content/view/carte-prepagate/ carte prepagate] [http://alvonina.ifrance.com/img/styles/ossezia-video/ ossezia video] [http://itsmeladuh.ifrance.com/content/view/robowar/ robowar] [http://itsmeladuh.ifrance.com/content/view/film-pieraccioni/ film pieraccioni] [http://mania555.ifrance.com/img/styles/volare-web.htm volare web] [http://itsmeladuh.ifrance.com/content/view/original-of/ original of the species] [http://faithib.ifrance.com/description/lib/locande.htm locande] [http://itsmeladuh.ifrance.com/content/view/testo-canzone/ testo canzone aicha in italiano] [http://bladiblada.ifrance.com/resources/articles/nokia.htm nokia 6220] [http://blackblackblack.ifrance.com/lib/domini.htm domini] [http://kirizz.ifrance.com/html/ablaze.htm ablaze] [http://bang-sigh.ifrance.com/images/small/testi-pupo/ testi pupo] [http://faithib.ifrance.com/description/lib/la-signora.htm la signora vestita di nero] [http://twobit77.ifrance.com/description/lib/shrek-soundtrack/ shrek soundtrack] [http://dgdeeper.ifrance.com/img/styles/birkenstock-donna.htm birkenstock donna] [http://soundwave106.ifrance.com/resources/articles/il-nostro/ il nostro prossimo] [http://soundwave106.ifrance.com/resources/articles/gmt/ gmt] [http://asing-argirl.ifrance.com/images/small/elettric-flying/ elettric flying] [http://nettikyzarc.ifrance.com/content/view/sharp-forno/ sharp forno microonde] [http://bang-sigh.ifrance.com/images/small/lg-fotocamera/ lg fotocamera] [http://mania555.ifrance.com/img/styles/aeronatica.htm aeronatica] [http://alvonina.ifrance.com/img/styles/hp-compaq/ hp compaq tc1100] [http://toupheefee.ifrance.com/text/directory/frigo-aeg/ frigo aeg santo] [http://hethrfethr77.ifrance.com/content/view/originalsin/ originalsin] [http://blackblackblack.ifrance.com/lib/donne-obese.htm donne obese] [http://blackblackblack.ifrance.com/lib/irradio-mp.htm irradio mp3 cd] [http://nettikyzarc.ifrance.com/content/view/nano-ipod/ nano ipod 4] [http://kirizz.ifrance.com/html/seredova-calendario.htm seredova calendario] [http://toupheefee.ifrance.com/text/directory/antz/ antz] [http://crazybird027.ifrance.com/view/new/cardinal-schuster/ cardinal schuster] [http://reikofanel.ifrance.com/web/deflorare.htm deflorare] [http://kirizz.ifrance.com/html/www-comune.htm www comune firenze] [http://kiravina.ifrance.com/html/la-torre.htm la torre di babele] [http://alvonina.ifrance.com/img/styles/orgia-di/ orgia di corfu] [http://alvonina.ifrance.com/img/styles/la-suora/ la suora giovane] [http://soundwave106.ifrance.com/resources/articles/acipenser/ acipenser] [http://twobit77.ifrance.com/description/lib/nomi-degli/ nomi degli artisti italiani] [http://blackblackblack.ifrance.com/lib/video-porno.htm video porno di pamela andersson] [http://alvonina.ifrance.com/img/styles/mokia/ mokia 6020] [http://crazybird027.ifrance.com/view/new/surf-nelle/ surf nelle mie vene] [http://sarah531.ifrance.com/lib/packaging-srl.htm packaging srl] [http://itsmeladuh.ifrance.com/content/view/midi-figli/ midi figli di pitagora] [http://reikofanel.ifrance.com/web/vos-veiz.htm vos veiz] [http://dgdeeper.ifrance.com/img/styles/terme-vals.htm terme vals] [http://bang-sigh.ifrance.com/images/small/bella-idiota/ bella idiota] [http://reikofanel.ifrance.com/web/viaggio-ultimo.htm viaggio ultimo minuto] [http://csmith06.ifrance.com/lib/euroxl.htm euroxl] [http://toupheefee.ifrance.com/text/directory/nije-ovo/ nije ovo moja noc] [http://bang-sigh.ifrance.com/images/small/javanoid/ javanoid] [http://kiravina.ifrance.com/html/canon-mvx.htm canon mvx 300] [http://crazybird027.ifrance.com/view/new/porri/ porri] [http://soundwave106.ifrance.com/resources/articles/renault-espace/ renault espace 2 serie] [http://crazybird027.ifrance.com/view/new/dubliners/ dubliners] [http://sarah531.ifrance.com/lib/new-mexico.htm new mexico cose fare] [http://toupheefee.ifrance.com/text/directory/kenwood-krf/ kenwood krf v5090d] [http://toupheefee.ifrance.com/text/directory/lecciso-loredana/ lecciso loredana sex] [http://mania555.ifrance.com/img/styles/baby-s.htm baby s gang] [http://twobit77.ifrance.com/description/lib/hard-disk/ hard disk portatile lacie 40] [http://kiravina.ifrance.com/html/home-theatre.htm home theatre wireless cinema] [http://csmith06.ifrance.com/lib/film-hard.htm film hard in formato quick time gratis] [http://soundwave106.ifrance.com/resources/articles/moto-gp/ moto gp 5] [http://kirizz.ifrance.com/html/le-ragazze.htm le ragazze di harvey] [http://twobit77.ifrance.com/description/lib/lettore-dvd/ lettore dvd con uscite audio] [http://sarah531.ifrance.com/lib/router-dlink.htm router dlink 504t] [http://kiravina.ifrance.com/html/masterizzatori-hp.htm masterizzatori hp] [http://bladiblada.ifrance.com/resources/articles/acer-.htm acer 19 lcd al1912s] [http://sarah531.ifrance.com/lib/koln-alberghi.htm koln alberghi e hotel] [http://twobit77.ifrance.com/description/lib/lanterna/ lanterna] [http://crazybird027.ifrance.com/view/new/mia-moglie/ mia moglie e l idraulico] [http://sarah531.ifrance.com/lib/ups-va.htm ups 1500va] [http://asing-argirl.ifrance.com/images/small/aficio/ aficio 1015] [http://faithib.ifrance.com/description/lib/sfondi-lazio.htm sfondi lazio] [http://kiravina.ifrance.com/html/files-codici.htm files codici seca da scaricare] [http://dgdeeper.ifrance.com/img/styles/ilguerriero.htm ilguerriero] [http://bang-sigh.ifrance.com/images/small/schermo/ schermo 15] [http://blackblackblack.ifrance.com/lib/cdc-columbus.htm cdc columbus] [http://soundwave106.ifrance.com/resources/articles/stradario-slovenia/ stradario slovenia] [http://crazybird027.ifrance.com/view/new/soffiatore-aspiratore/ soffiatore aspiratore] [http://toupheefee.ifrance.com/text/directory/una-chica/ una chica goos] [http://mania555.ifrance.com/img/styles/intervideo.htm intervideo] [http://blackblackblack.ifrance.com/lib/la-historia.htm la historia del carro] [http://toupheefee.ifrance.com/text/directory/vie-di/ vie di roma] [http://crazybird027.ifrance.com/view/new/calcetto-nike/ calcetto nike 90] [http://blackblackblack.ifrance.com/lib/kurisches-haff.htm kurisches haff] [http://nettikyzarc.ifrance.com/content/view/setimo-cielo/ setimo cielo nuove puntate] [http://reikofanel.ifrance.com/web/barriere-coralline.htm barriere coralline] [http://toupheefee.ifrance.com/text/directory/ati-radeon/ ati radeon 128bit agp 4x] [http://mania555.ifrance.com/img/styles/pioneer-dvrd.htm pioneer dvr110d] [http://mania555.ifrance.com/img/styles/vtol.htm vtol] [http://toupheefee.ifrance.com/text/directory/commedie-musicali/ commedie musicali] [http://twobit77.ifrance.com/description/lib/audio-analogue/ audio analogue] [http://sarah531.ifrance.com/lib/power-shot.htm power shot s2is] [http://csmith06.ifrance.com/lib/turn-me.htm turn me on] [http://itsmeladuh.ifrance.com/content/view/tv/ tv 4 3] {{task}}
Compute the sum of the elements of an Array
Line 11:
$var:=0
For ($i;1;Size of array($list))
$var:=$var
End for
Line 20:
Sum : Integer := 0;
for I in Int_Array'range loop
Sum := Sum
end loop;
Line 30:
repeat with i in array
-- very important -- list index starts at 1 not 0
set product to product
end repeat
Line 42:
50 REM Find the sum of elements in the array
60 SUM = 0
70 FOR I = 1 TO 5: SUM = SUM
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;
}
Line 103:
int arg_length = arg.Length;
for( int i = 0; i < arg_length; i
value
Line 111:
int sum = 0;
int[] arg = { 1, 2, 3, 4, 5 };
foreach (int value in arg) sum
==[[Clean]]==
Line 128:
(defparameter *data* #(1 2 3 4 5))
(reduce #'
==[[Delphi]]==
Line 146:
pragma.enable("accumulator")
accum 0 for x in [1,2,3,4,5] { _
==[[Erlang]]==
Line 168:
0;
sum_rec([Head|Tail]) ->
Head
% tail-recursive definition:
Line 176:
Acc;
sum_tail([Head|Tail], Acc) ->
sum_tail(Tail, Head
==[[Forth]]==
Line 183:
: sum ( addr cnt -- n )
0 -rot
cells bounds do i @
Line 193:
dim sum as integer = 0
for index as integer = lbound(array) to ubound(array)
sum
next
Line 201:
let values = [1..10]
sum values -- the easy way
foldl (
==[[IDL]]==
Line 214:
int[] arg = new int[] { 1,2,3,4,5 };
for (int i: arg)
value
==[[JavaScript]]==
Line 222:
var sum = 0;
for(var i in array)
sum
==[[Perl]]==
Line 230:
my $var;
my @list = (1, 2, 3);
$var
Alternate
Line 245:
my $acc = 0;
my @list = qw(1 2 3)
map { $acc
==[[PHP]]==
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 286:
ary = [1,2,3,4,5]
sum = ary.inject{|currentSum,element|currentSum
# => 15
Line 292:
[[Category:Scala]]
val array = Array(1,2,3,4,5)
val sum = array.foldLeft(0)(_
This is a shortcut for
val sum = array.foldLeft(0){(currentSum, element) => currentSum
==[[Seed7]]==
Line 307:
begin
for value range valueArray do
sum
end for;
end func;
Line 319:
val array = [1,2,3,4,5];
foldl op
==[[Tcl]]==
Line 326:
Assuming the values are in a list named <tt>listname</tt>:
set result [expr [join $listname
==[[Toka]]==
Line 332:
[ ( array size -- sum )
>r 0 r> [ over i swap get-element
==[[UNIX Shell]]==
Line 344:
list="1 2 3"
for n in $list
do sum="$(($sum
done
echo $sum
Line 352:
sum=0
for n
do sum="$(($sum
done
echo $sum
Line 360:
sum=0
while read n
do sum="$(($sum
done
echo $sum
Line 371:
SUM=0;
for i in $LIST; do
SUM=$[$SUM
done;
echo $SUM
|
Revision as of 07:40, 1 September 2007
basi karaoke gratis hypnerotomachia poliphili e invece no yaris www aziendaagricola it ufficio frosinone ashampoo photo commander www 6sicuro it quando la banda passo lavatrice alto campitello matese olympus 6 elster nero di pari passo con lamore e la morte pneumotorace edaphosaurus vorrei volare al volante rivista auto heeresgeschichtliches museum wien fhdg sony cyber shot dscw7 time stood still auto modelli a scoppio eduardo de crescenzo logitech cordless gamepad xbox mas bekrije www sexogratis com carducci sintonizzatore tv auto paola barale video codici seca1 sesso annunci gratis boogeman memory stick duo gb golf it assicurazione ferrara hitachi lcd tv cuando bailas asi hombres peludos il cielo su roma colle der fomento lettore mp3 packard google nl asus 620 gps austerlitz paese dei balocchi ruslana ladosi fucili da cecchino vivoperlei ringtone toshiba m60 146 stanton brescia holding out for a hero tyler bonnie visiera casco escort boy merini alda rex piano cottura la mia ex harman kardon cd sony fm beauty farm lago di garda piccoli elettrodomestico gobli dsb 707 fta abit nf7m on a g air vecchie nude spicy mix frigorifero 85 km0 audi a3 sportback diesel auto km 0 hp ipaq hw6515 televisori combo filmati e offerte per everquest video killed the radio star suluk vidracco ultima mujer duello a santa cruz melissa 18 temi italiano esami di maturita 2004 midi file 2004 centro studi ps2 accessori il gatto e il topo sambiase maggioli spa shadow 750 sole spento timoria cliamx calcetto nike ho trovato lamore the king of figther battaglie spaziali congiura di catilina la ds online maturita prima prova 2004 wellness potenza logitech notebook na telefonata fisarmonica impazzita midi celebrity porn mezz u mare sex nude teen tommy vee e carolina tosse grassa sata melfi paul k carte prepagate ossezia video robowar film pieraccioni volare web original of the species locande testo canzone aicha in italiano nokia 6220 domini ablaze testi pupo la signora vestita di nero shrek soundtrack birkenstock donna il nostro prossimo gmt elettric flying sharp forno microonde lg fotocamera aeronatica hp compaq tc1100 frigo aeg santo originalsin donne obese irradio mp3 cd nano ipod 4 seredova calendario antz cardinal schuster deflorare www comune firenze la torre di babele orgia di corfu la suora giovane acipenser nomi degli artisti italiani video porno di pamela andersson mokia 6020 surf nelle mie vene packaging srl midi figli di pitagora vos veiz terme vals bella idiota viaggio ultimo minuto euroxl nije ovo moja noc javanoid canon mvx 300 porri renault espace 2 serie dubliners new mexico cose fare kenwood krf v5090d lecciso loredana sex baby s gang hard disk portatile lacie 40 home theatre wireless cinema film hard in formato quick time gratis moto gp 5 le ragazze di harvey lettore dvd con uscite audio router dlink 504t masterizzatori hp acer 19 lcd al1912s koln alberghi e hotel lanterna mia moglie e l idraulico ups 1500va aficio 1015 sfondi lazio files codici seca da scaricare ilguerriero schermo 15 cdc columbus stradario slovenia soffiatore aspiratore una chica goos intervideo la historia del carro vie di roma calcetto nike 90 kurisches haff setimo cielo nuove puntate barriere coralline ati radeon 128bit agp 4x pioneer dvr110d vtol commedie musicali audio analogue power shot s2is turn me on tv 4 3
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Compute the sum of the elements of an Array
4D
ARRAY INTEGER($list;0) 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
Int_Array : array(1..10) of Integer := (1,2,3,4,5,6,7,8,9,10); Sum : Integer := 0; for I in Int_Array'range loop Sum := Sum Int_Array(I); end loop;
AppleScript
set array to {1, 2, 3, 4, 5} set product to 0 repeat with i in array -- very important -- list index starts at 1 not 0 set product to product i end repeat
BASIC
10 REM Create an array with some test data in it 20 DIM ARRAY(5) 30 FOR I = 1 TO 5: READ ARRAY(I): NEXT I 40 DATA 1, 2, 3, 4, 5 50 REM Find the sum of elements in the array 60 SUM = 0 70 FOR I = 1 TO 5: SUM = SUM ARRAY(I): NEXT I 80 PRINT "The sum is ";SUM
C
Compiler: gcc 4.0.2
int main( int argc, char* argv[] ) { int list[] = { 1, 2, 3 } ; int sum = 0 ; for( int i = 0 ; i < 3 ; i ) { sum = list[i]; } }
Alternate
#include <numeric> int main( int argc, char* argv[] ) { int list[] = { 1, 2, 3 } ; std::accumulate(list, list 3, 0); return 0; }
template alternative
template <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; }
#include <iostream> using std::cout; using std::endl;
int main (void) { int aint[] = {1, 2, 3}; cout << sum(aint,3) << endl; float aflo[] = {1.1, 2.02, 3.003, 4.0004}; cout << sum(aflo,4) << endl; return 0; }
C#
int value = 0; int[] arg = { 1,2,3,4,5 }; int arg_length = arg.Length;
for( int i = 0; i < arg_length; i ) value = arg[i];
Alternate
int sum = 0; int[] arg = { 1, 2, 3, 4, 5 }; foreach (int value in arg) sum = value;
Clean
array = {1, 2, 3, 4, 5} Start = sum [x \\ x <-: array]
ColdFusion
<cfset myArray = listToArray("1,2,3,4,5")> #arraySum(myArray)#
Common Lisp
(defparameter *data* #(1 2 3 4 5)) (reduce #' *data*)
Delphi
[[Category:Delphi]
Compiler: All
var Ints : array[1..5] of integer = (1,2,3,4,5) ; i,Sum : integer = 0 ; begin for i := 1 to length(ints) do inc(sum,ints[i]) ; end;
E
pragma.enable("accumulator") accum 0 for x in [1,2,3,4,5] { _ x }
Erlang
Using the standard libraries:
% create the list: L = lists:seq(1, 10).
% and compute its sum: S = lists:sum(L).
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).
Forth
: sum ( addr cnt -- n ) 0 -rot cells bounds do i @ cell loop ;
FreeBASIC
dim array(4) as integer = { 1, 2, 3, 4, 5 }
dim sum as integer = 0 for index as integer = lbound(array) to ubound(array) sum = array(index) next
Haskell
let values = [1..10] sum values -- the easy way foldl ( ) 0 values -- the hard way
IDL
result = total(array)
Java
int value = 0; int[] arg = new int[] { 1,2,3,4,5 }; for (int i: arg) value = i;
JavaScript
var array = [1, 2, 3, 4, 5]; var sum = 0; for(var i in array) sum = array[i];
Perl
Interpeter: Perl
my $var; my @list = (1, 2, 3); $var = $_ for (@list);
Alternate
Libraries: List::Util
use List::Util 'sum'; my @list = (1, 2, 3); my $var = sum @list;
Alternate
# TMTOWTDI
my $acc = 0; my @list = qw(1 2 3) map { $acc = $_ } @list
PHP
$list = array(1,2,3,4,5,6,7,8,9); echo array_sum($list);
Pop11
Simple loop:
lvars i, sum = 0, ar = {1 2 3 4 5 6 7 8 9}; for i from 1 to length(ar) do ar(i) sum -> sum; endfor;
One can alternativly use second order iterator:
lvars sum = 0, ar = {1 2 3 4 5 6 7 8 9}; appdata(ar, procedure(x); x sum -> sum; endprocedure);
Prolog
sum([],0). sum([H|T],X) :- sum(T,Y), X is H Y.
test
:- sum([1,2,3,4,5,6,7,8,9],X). X =45;
Python
Interpeter: Python 2.5
total = sum([1, 2, 3, 4, 5, 6, 7, 8, 9])
Ruby
ary = [1,2,3,4,5] sum = ary.inject{|currentSum,element|currentSum element} # => 15
Scala
val array = Array(1,2,3,4,5) val sum = array.foldLeft(0)(_ _)
This is a shortcut for
val sum = array.foldLeft(0){(currentSum, element) => currentSum element}
Seed7
const func integer: sumArray (in array integer: valueArray) is func result var integer: sum is 0; local var integer: value is 0; begin for value range valueArray do sum := value; end for; end func;
Call this function with:
writeln(sumArray([](1, 2, 3, 4, 5)));
Standard ML
val array = [1,2,3,4,5]; foldl op 0 array;
Tcl
Assuming the values are in a list named listname:
set result [expr [join $listname ]]
Toka
[ ( array size -- sum ) >r 0 r> [ over i swap get-element ] iterate nip ] is sum-array
UNIX Shell
Interpreter: NetBSD 3.0's ash
From an internal variable, $IFS delimited:
sum=0 list="1 2 3" for n in $list do sum="$(($sum $n))" done echo $sum
From the argument list (ARGV):
sum=0 for n do sum="$(($sum $n))" done echo $sum
From STDIN, one integer per line:
sum=0 while read n do sum="$(($sum $n))" done echo $sum
Interpreter: GNU bash, version 3.2.0(1)-release (i386-unknown-freebsd6.1)
From variable:
LIST='20 20 2'; SUM=0; for i in $LIST; do SUM=$[$SUM $i]; done; echo $SUM