Sum of Array: Difference between revisions
revert spam |
mNo edit summary |
||
Line 1:
[http://liubash.ifrance.com/new/juhnke.htm juhnke] [http://thecakeblog.ifrance.com/articles/bond/ bond] [http://chrystiala.ifrance.com/library/testi-canzoni.htm testi canzoni dell album guilty dei blue] [http://ohmygoshalix.ifrance.com/blog/ragazze-puttane.htm ragazze puttane] [http://ohmygoshalix.ifrance.com/blog/intel-pentium.htm intel pentium 4 3 0 ghz box 1mb] [http://makkiesan.ifrance.com/suite-n.htm suite n 7 handel] [http://emrinalexander.ifrance.com/styles/villaggio-nuraghe.htm villaggio nuraghe] [http://seachildelf.ifrance.com/resources/philips-bcs/ philips 170b5cs] [http://pouringsunny.ifrance.com/description/sofia-marinova/ sofia marinova] [http://thecakeblog.ifrance.com/articles/nvidia-geforce/ nvidia geforce 6600 gt] [http://feelosof.ifrance.com/description/disalberare/ disalberare] [http://cikumuffin.ifrance.com/topic/e-ti/ e ti amo masini] [http://listsobacka.ifrance.com/small/escuela-montalban.htm escuela montalban] [http://chrystiala.ifrance.com/library/evangelista.htm evangelista] [http://pouringsunny.ifrance.com/description/ispettore-ambiente/ ispettore ambiente] [http://feelosof.ifrance.com/description/serra-di/ serra di compostaggio] [http://beatpoetsa.ifrance.com/description/pentium-.htm pentium 4 d] [http://thecakeblog.ifrance.com/articles/tribunale-napoli/ tribunale napoli lavoro] [http://shmarodral.ifrance.com/text/audi-a.htm audi a3 sportback km zero] [http://seachildelf.ifrance.com/resources/midi-mexicana/ midi mexicana] [http://jazzyjoe.ifrance.com/filmer-sir/ filmer sir robert] [http://jojorock.ifrance.com/articles/mp-gb/ mp3 gb divx] [http://seachildelf.ifrance.com/resources/percussionisti/ percussionisti] [http://thecakeblog.ifrance.com/articles/frasi-auguri/ frasi auguri matrimonio ingles] [http://ohmygoshalix.ifrance.com/blog/subaru-outback.htm subaru outback 30] [http://jene7777777.ifrance.com/new/ferro-da.htm ferro da stiro rowenta con caldaia] [http://listsobacka.ifrance.com/small/dial-the.htm dial the] [http://belikan.ifrance.com/library/senza-luce.htm senza luce e colore] [http://jene7777777.ifrance.com/new/prestito-personali.htm prestito personali catania] [http://listsobacka.ifrance.com/small/usb-sd.htm usb sd fm] [http://shotlandetz.ifrance.com/blog/cuffie-con/ cuffie con radio integrata fm] [http://animaetrix00.ifrance.com/content/lancia-y/ lancia y 2001] [http://eccoblackfin.ifrance.com/html/elezioni-europei.htm elezioni europei] [http://seachildelf.ifrance.com/resources/taj-mahal/ taj mahal salon de bahia] [http://listsobacka.ifrance.com/small/galleon-mix.htm galleon mix] [http://emrinalexander.ifrance.com/styles/un-medico.htm un medico in famiglia 5] [http://firejedi.ifrance.com/new/inglesina-emma/ inglesina emma] [http://beatpoetsa.ifrance.com/description/paris-francia.htm paris (francia)] [http://beatpoetsa.ifrance.com/description/di-magia.htm di magia] [http://firejedi.ifrance.com/new/videoclip-smackdown/ videoclip smackdown] [http://liubash.ifrance.com/new/scarpe-onitsuka.htm scarpe onitsuka] [http://jazzyjoe.ifrance.com/hp-p/ hp 4p hp toner] [http://thecakeblog.ifrance.com/articles/cd-peter/ cd peter gabriel] [http://liubash.ifrance.com/new/cercasi-trans.htm cercasi trans] [http://beatpoetsa.ifrance.com/description/gran-turismo.htm gran turismo 4 in musica] [http://jene7777777.ifrance.com/new/viva-la.htm viva la pappa col pomodoro] [http://chrystiala.ifrance.com/library/stivali-collant.htm stivali collant] [http://infunt.ifrance.com/articles/notebook-masterizzatore/ notebook masterizzatore dvd interno] [http://chrystiala.ifrance.com/library/ati-radeon.htm ati radeon 9600 da 256mb 256bit] [http://beatpoetsa.ifrance.com/description/sito-sms.htm sito sms gratis] [http://emrinalexander.ifrance.com/styles/il-motomondiale.htm il motomondiale turbo xt] [http://infunt.ifrance.com/articles/multi-tap/ multi tap ps2] [http://animaetrix00.ifrance.com/content/wild-dance/ wild dance mpe] [http://ohmygoshalix.ifrance.com/blog/e-per.htm e per te] [http://eccoblackfin.ifrance.com/html/morellino-di.htm morellino di scansano] [http://feelosof.ifrance.com/description/brandl-johann/ brandl johann] [http://emrinalexander.ifrance.com/styles/kierra-knightly.htm kierra knightly] [http://jojorock.ifrance.com/articles/pentax-obiettivo/ pentax obiettivo] [http://animaetrix00.ifrance.com/content/il-solitario/ il solitario del west] [http://infunt.ifrance.com/articles/babol-puzle/ babol puzle] [http://eccoblackfin.ifrance.com/html/la-finta.htm la finta giardiniera] [http://emrinalexander.ifrance.com/styles/mirabassi.htm mirabassi] [http://makkiesan.ifrance.com/telecamera-antifurto.htm telecamera antifurto wireless] [http://listsobacka.ifrance.com/small/crea-corpi.htm crea corpi] [http://eccoblackfin.ifrance.com/html/traduzione-moondance.htm traduzione moondance] [http://liubash.ifrance.com/new/ufficio-delle.htm ufficio delle entrate] [http://infunt.ifrance.com/articles/foto-amatoriali/ foto amatoriali di donne spogliate] [http://jazzyjoe.ifrance.com/v-td/ v9999 td 128mb] [http://shotlandetz.ifrance.com/blog/modelli-excel/ modelli excel di contabilita] [http://seachildelf.ifrance.com/resources/bergamotti/ bergamotti] [http://beatpoetsa.ifrance.com/description/gps-nemerix.htm gps nemerix] [http://shotlandetz.ifrance.com/blog/wierni/ wierni] [http://lethalga.ifrance.com/topic/memphis-bells/ memphis bells] [http://shmarodral.ifrance.com/text/senza-scampo.htm senza scampo] [http://thecakeblog.ifrance.com/articles/playstation-joystick/ playstation joystick] [http://beatpoetsa.ifrance.com/description/soap-opera.htm soap opera] [http://pouringsunny.ifrance.com/description/confermato-il/ confermato il ritorno di indiana jones nel 2007] [http://listsobacka.ifrance.com/small/delibes-miguel.htm delibes miguel] [http://shotlandetz.ifrance.com/blog/bertolazzi-carlo/ bertolazzi carlo] [http://pouringsunny.ifrance.com/description/xevo/ xevo] [http://seachildelf.ifrance.com/resources/caccia-anatre/ caccia anatre] [http://emrinalexander.ifrance.com/styles/cieli-azzuri.htm cieli azzuri pupo] [http://chrystiala.ifrance.com/library/amore-s.htm amore s] [http://infunt.ifrance.com/articles/scale-alluminio/ scale alluminio] [http://makkiesan.ifrance.com/deca.htm deca] [http://jene7777777.ifrance.com/new/channel-tv.htm channel tv] [http://feelosof.ifrance.com/description/rivenditori-calabria/ rivenditori calabria] [http://cikumuffin.ifrance.com/topic/philips-cordless/ philips cordless 311] [http://emrinalexander.ifrance.com/styles/lets-go.htm lets go straight] [http://jazzyjoe.ifrance.com/lampada-da/ lampada da testa] [http://shmarodral.ifrance.com/text/decorare-torta.htm decorare torta] [http://jojorock.ifrance.com/articles/enola-gay/ enola gay] [http://ohmygoshalix.ifrance.com/blog/calcio-a.htm calcio a tre] [http://emrinalexander.ifrance.com/styles/microsoft-visual.htm microsoft visual basic] [http://eccoblackfin.ifrance.com/html/la-donna.htm la donna quale animale si scopa] [http://makkiesan.ifrance.com/ricette-per.htm ricette per cucinare il pavone] [http://emrinalexander.ifrance.com/styles/myimmortal-mid.htm myimmortal mid] [http://pouringsunny.ifrance.com/description/is-it/ is it cos i m cod] [http://infunt.ifrance.com/articles/trimone/ trimone] [http://listsobacka.ifrance.com/small/champions-league.htm champions league risultati] [http://liubash.ifrance.com/new/ita-siena.htm ita siena] [http://infunt.ifrance.com/articles/lacie-hard/ lacie hard disk divx] [http://beatpoetsa.ifrance.com/description/casting-gf.htm casting gf5] [http://eccoblackfin.ifrance.com/html/pioneer-dcs.htm pioneer dcs 535] [http://jazzyjoe.ifrance.com/opel-/ opel vectra 25 v6 24v 4p sport] [http://makkiesan.ifrance.com/renato-zero.htm renato zero l equilibrista] [http://beatpoetsa.ifrance.com/description/lebrecht-danilo.htm lebrecht danilo] [http://jojorock.ifrance.com/articles/auto-noleggio/ auto noleggio faenza] [http://emrinalexander.ifrance.com/styles/powerbook-apple.htm powerbook apple] [http://pouringsunny.ifrance.com/description/sd-wi/ sd wi fi] [http://shotlandetz.ifrance.com/blog/silvio-gigli/ silvio gigli] [http://seachildelf.ifrance.com/resources/lexus-rx/ lexus rx 400] [http://jene7777777.ifrance.com/new/fighette-vergini.htm fighette vergini] [http://feelosof.ifrance.com/description/nokia/ nokia 5125] [http://ohmygoshalix.ifrance.com/blog/porno-en.htm porno en dibujos] [http://firejedi.ifrance.com/new/bocelli-vivo/ bocelli vivo per lei] [http://listsobacka.ifrance.com/small/finanziamento-piccola.htm finanziamento piccola impresa] [http://infunt.ifrance.com/articles/villaggio-spagna/ villaggio spagna] [http://animaetrix00.ifrance.com/content/fellowship/ fellowship] [http://liubash.ifrance.com/new/benediro-il.htm benediro il signore] [http://shotlandetz.ifrance.com/blog/traduzione-i/ traduzione i don t want you bach] [http://feelosof.ifrance.com/description/playstation-console/ playstation console ps2] [http://jene7777777.ifrance.com/new/ohne-dich.htm ohne dich rammstein] [http://ohmygoshalix.ifrance.com/blog/racconti-di.htm racconti di sesso con i cavalli] [http://animaetrix00.ifrance.com/content/photo-eminem/ photo eminem] [http://jazzyjoe.ifrance.com/inizio-scuole/ inizio scuole] [http://seachildelf.ifrance.com/resources/canon-mvx/ canon mvx 300] [http://thecakeblog.ifrance.com/articles/scarafaggi/ scarafaggi] [http://lethalga.ifrance.com/topic/before-you/ before you acuse me] [http://jazzyjoe.ifrance.com/scuola-di/ scuola di liuteria] [http://jene7777777.ifrance.com/new/keynes-john.htm keynes john neville] [http://cikumuffin.ifrance.com/topic/esecuzione-ostaggi/ esecuzione ostaggi] [http://shotlandetz.ifrance.com/blog/ronald-reagan/ ronald reagan] [http://jene7777777.ifrance.com/new/bluetooth-mini.htm bluetooth mini keyboard] [http://shotlandetz.ifrance.com/blog/jeanette-hold/ jeanette hold the line] [http://emrinalexander.ifrance.com/styles/dvd-film.htm dvd film gratis] [http://firejedi.ifrance.com/new/pajas/ pajas] [http://shotlandetz.ifrance.com/blog/i-vinti/ i vinti] [http://animaetrix00.ifrance.com/content/lavaggio-auto/ lavaggio auto] [http://firejedi.ifrance.com/new/iceberg-effusion/ iceberg effusion] [http://lethalga.ifrance.com/topic/panasonic-nv/ panasonic nv gs22] [http://jene7777777.ifrance.com/new/forem.htm forem] [http://jene7777777.ifrance.com/new/copertina-cd.htm copertina cd hit mania dance 2006] [http://emrinalexander.ifrance.com/styles/actua-tennis.htm actua tennis] [http://ohmygoshalix.ifrance.com/blog/wwww-sms.htm wwww sms it] [http://belikan.ifrance.com/library/cuore-uno.htm cuore uno zingaro] [http://emrinalexander.ifrance.com/styles/mamma-di.htm mamma di un angelo] [http://infunt.ifrance.com/articles/webcam-live/ webcam live pro] [http://makkiesan.ifrance.com/piera.htm piera] [http://listsobacka.ifrance.com/small/una-demo.htm una demo per airport tycoon 2] [http://belikan.ifrance.com/library/decoder-usb.htm decoder usb pc] [http://emrinalexander.ifrance.com/styles/tv-plasma.htm tv plasma 42 phs] [http://animaetrix00.ifrance.com/content/ubanghi/ ubanghi] [http://ohmygoshalix.ifrance.com/blog/wwww-mappy.htm wwww mappy com] [http://seachildelf.ifrance.com/resources/brother-c/ brother 210c] [http://feelosof.ifrance.com/description/concerto-pfm/ concerto pfm monza] [http://emrinalexander.ifrance.com/styles/premi-tesi.htm premi tesi] [http://pouringsunny.ifrance.com/description/billinger-richard/ billinger richard] [http://lethalga.ifrance.com/topic/fermata-per/ fermata per dodici ore] [http://feelosof.ifrance.com/description/justine-una/ justine una relazione privata] [http://thecakeblog.ifrance.com/articles/wawes-of/ wawes of luv midi 2 black] [http://beatpoetsa.ifrance.com/description/alicebusiness-it.htm alicebusiness it] [http://shotlandetz.ifrance.com/blog/ricette-di/ ricette di verdure] [http://seachildelf.ifrance.com/resources/navigatori-car/ navigatori car gps] [http://seachildelf.ifrance.com/resources/eos-ds/ eos 1ds canon] [http://shmarodral.ifrance.com/text/abbigliamento-uomo.htm abbigliamento uomo energie] [http://feelosof.ifrance.com/description/racconti-porno/ racconti porno gay] [http://cikumuffin.ifrance.com/topic/stampanti-hp/ stampanti hp laserjet 2550n] [http://makkiesan.ifrance.com/collane-vetro.htm collane vetro] [http://jojorock.ifrance.com/articles/hockey-ice/ hockey ice] [http://jene7777777.ifrance.com/new/dvd-.htm dvd 1 4gb] [http://infunt.ifrance.com/articles/instant-video/ instant video] [http://jazzyjoe.ifrance.com/graz-cose/ graz cose fare] [http://belikan.ifrance.com/library/mobile-cristallo.htm mobile cristallo plasma] [http://cikumuffin.ifrance.com/topic/furness/ furness] [http://animaetrix00.ifrance.com/content/overlap/ overlap] [http://liubash.ifrance.com/new/vfa.htm vfa] [http://chrystiala.ifrance.com/library/bleh.htm bleh] [http://thecakeblog.ifrance.com/articles/matrox-rtx/ matrox rtx10] [http://emrinalexander.ifrance.com/styles/yasmine-bleeth.htm yasmine bleeth nuda] [http://infunt.ifrance.com/articles/cecilia-finotti/ cecilia finotti] [http://shotlandetz.ifrance.com/blog/iriver-ifp/ iriver ifp] [http://lethalga.ifrance.com/topic/squadra-francese/ squadra francese nuda] [http://liubash.ifrance.com/new/harjai.htm harjai] [http://thecakeblog.ifrance.com/articles/pontignano-siena/ pontignano siena] [http://cikumuffin.ifrance.com/topic/lesbianas/ lesbianas] [http://animaetrix00.ifrance.com/content/asus-anxla/ asus a7n8xla] [http://beatpoetsa.ifrance.com/description/bebe-confort.htm bebe confort iseos] [http://beatpoetsa.ifrance.com/description/stai-con.htm stai con meu] [http://shotlandetz.ifrance.com/blog/inglese-corso/ inglese corso] [http://emrinalexander.ifrance.com/styles/giochi-calcio.htm giochi calcio pc] [http://pouringsunny.ifrance.com/description/garou-esmeralda/ garou esmeralda] [http://chrystiala.ifrance.com/library/batteria-sony.htm batteria sony t630] [http://feelosof.ifrance.com/description/paco-de/ paco de lucia light and shade] [http://shotlandetz.ifrance.com/blog/nikon-mh/ nikon mh53] [http://makkiesan.ifrance.com/marlyn-manson.htm marlyn manson] [http://pouringsunny.ifrance.com/description/cosmetico-prodotti/ cosmetico prodotti bellezza] [http://belikan.ifrance.com/library/gran-turismo.htm gran turismo 4 potrebbe ritardare anche in usa] [http://jazzyjoe.ifrance.com/leatherman-wave/ leatherman wave] [http://lethalga.ifrance.com/topic/mp-mb/ mp3 128mb] [http://animaetrix00.ifrance.com/content/everybodies-change/ everybodies change kings] [http://jojorock.ifrance.com/articles/panasonic-scpm/ panasonic scpm21] [http://shmarodral.ifrance.com/text/dvd-rw.htm dvd rw esterno firewire] [http://cikumuffin.ifrance.com/topic/vampire-the/ vampire the masquerade bloodlines] [http://jazzyjoe.ifrance.com/video-dell/ video dell attentato in america dell 11] [http://seachildelf.ifrance.com/resources/senza-far/ senza far rumore] [http://eccoblackfin.ifrance.com/html/libera-professione.htm libera professione] [http://shmarodral.ifrance.com/text/foto-berry.htm foto berry white] [http://jazzyjoe.ifrance.com/volkswagen-golf/ volkswagen golf 1600] [http://animaetrix00.ifrance.com/content/monitor-lcd/ monitor lcd dvi 19] [http://listsobacka.ifrance.com/small/liviu-vasilica.htm liviu vasilica] [http://listsobacka.ifrance.com/small/misurini.htm misurini] [http://jene7777777.ifrance.com/new/www-movilnet.htm www movilnet com] [http://liubash.ifrance.com/new/emp.htm emp 30] [http://animaetrix00.ifrance.com/content/dedicato-a/ dedicato a una stella] [http://belikan.ifrance.com/library/hotel-caesar.htm hotel caesar] [http://jazzyjoe.ifrance.com/nuevas-normas/ nuevas normas de trafico] [http://feelosof.ifrance.com/description/due-di/ due di raf] [http://chrystiala.ifrance.com/library/mac-speaker.htm mac speaker e cuffie] [http://shotlandetz.ifrance.com/blog/procedure-delle/ procedure delle asl] [http://feelosof.ifrance.com/description/testo-canzone/ testo canzone aicha in italiano] [http://listsobacka.ifrance.com/small/tram.htm tram] [http://beatpoetsa.ifrance.com/description/elenco-rivenditori.htm elenco rivenditori fossil toscana] [http://lethalga.ifrance.com/topic/duplex-/ duplex un appartamento per tre] [http://liubash.ifrance.com/new/week-end.htm week end a parigi] [http://shmarodral.ifrance.com/text/athlete.htm athlete] [http://animaetrix00.ifrance.com/content/il-portiere/ il portiere di notte enrico ruggeri] [http://eccoblackfin.ifrance.com/html/o-c.htm o c soundtrack] [http://jazzyjoe.ifrance.com/srl-studio/ srl studio consulenza tributaria e del lavoro roma] [http://thecakeblog.ifrance.com/articles/fotos-di/ fotos di donas colombianas] [http://ohmygoshalix.ifrance.com/blog/calendari-george.htm calendari george clooney] [http://infunt.ifrance.com/articles/jennifer-hawkins/ jennifer hawkins nude] [http://jene7777777.ifrance.com/new/kate-rose.htm kate rose] [http://ohmygoshalix.ifrance.com/blog/codici-tps.htm codici tps] [http://makkiesan.ifrance.com/sviluppa-numeri.htm sviluppa numeri superenalotto] [http://ohmygoshalix.ifrance.com/blog/macchina-per.htm macchina per il pane delonghi] [http://thecakeblog.ifrance.com/articles/desiderando-giulia/ desiderando giulia] [http://firejedi.ifrance.com/new/ubuntu/ ubuntu] [http://liubash.ifrance.com/new/e-ti.htm e ti amo] [http://shmarodral.ifrance.com/text/tariffa-notaio.htm tariffa notaio] [http://makkiesan.ifrance.com/frasi-di.htm frasi di ringraziamento per lutto] [http://feelosof.ifrance.com/description/gioco-sony/ gioco sony ericsson p800] [http://feelosof.ifrance.com/description/la-notte/ la notte della taranta cd dvd] [http://lethalga.ifrance.com/topic/tutto-quello/ tutto quello che un uomo puo fare] [http://jazzyjoe.ifrance.com/jimny-suzuki/ jimny suzuki] [http://thecakeblog.ifrance.com/articles/jonni-dorelli/ jonni dorelli] [http://shmarodral.ifrance.com/text/codice-magnum.htm codice magnum] [http://lethalga.ifrance.com/topic/i-cavalieri/ i cavalieri del drago giorgio vanni] [http://jene7777777.ifrance.com/new/jeff-stryker.htm jeff stryker] [http://listsobacka.ifrance.com/small/www-gta.htm www gta vice city it] {{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 157:
% and compute its sum:
2000
S = lists:sum(L).
Line 168 ⟶ 170:
0;
sum_rec([Head|Tail]) ->
Head
% tail-recursive definition:
Line 176 ⟶ 178:
Acc;
sum_tail([Head|Tail], Acc) ->
sum_tail(Tail, Head
==[[Forth]]==
Line 183 ⟶ 185:
: sum ( addr cnt -- n )
0 -rot
cells bounds do i @
Line 193 ⟶ 195:
dim sum as integer = 0
for index as integer = lbound(array) to ubound(array)
sum
next
Line 201 ⟶ 203:
let values = [1..10]
sum values -- the easy way
foldl (
==[[IDL]]==
Line 214 ⟶ 216:
int[] arg = new int[] { 1,2,3,4,5 };
for (int i: arg)
value
==[[JavaScript]]==
Line 222 ⟶ 224:
var sum = 0;
for(var i in array)
sum
==[[Perl]]==
Line 230 ⟶ 232:
my $var;
my @list = (1, 2, 3);
$var
Alternate
Line 245 ⟶ 247:
my $acc = 0;
my @list = qw(1 2 3)
map { $acc
==[[PHP]]==
Line 260 ⟶ 262:
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 ⟶ 268:
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 ⟶ 288:
ary = [1,2,3,4,5]
sum = ary.inject{|currentSum,element|currentSum
# => 15
Line 292 ⟶ 294:
[[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 ⟶ 309:
begin
for value range valueArray do
sum
end for;
end func;
Line 319 ⟶ 321:
val array = [1,2,3,4,5];
foldl op
==[[Tcl]]==
Line 326 ⟶ 328:
Assuming the values are in a list named <tt>listname</tt>:
set result [expr [join $listname
==[[Toka]]==
Line 332 ⟶ 334:
[ ( array size -- sum )
>r 0 r> [ over i swap get-element
==[[UNIX Shell]]==
Line 344 ⟶ 346:
list="1 2 3"
for n in $list
do sum="$(($sum
done
echo $sum
Line 352 ⟶ 354:
sum=0
for n
do sum="$(($sum
done
echo $sum
Line 360 ⟶ 362:
sum=0
while read n
do sum="$(($sum
done
echo $sum
Line 371 ⟶ 373:
SUM=0;
for i in $LIST; do
SUM=$[$SUM
done;
echo $SUM
|
Revision as of 17:48, 10 September 2007
juhnke bond testi canzoni dell album guilty dei blue ragazze puttane intel pentium 4 3 0 ghz box 1mb suite n 7 handel villaggio nuraghe philips 170b5cs sofia marinova nvidia geforce 6600 gt disalberare e ti amo masini escuela montalban evangelista ispettore ambiente serra di compostaggio pentium 4 d tribunale napoli lavoro audi a3 sportback km zero midi mexicana filmer sir robert mp3 gb divx percussionisti frasi auguri matrimonio ingles subaru outback 30 ferro da stiro rowenta con caldaia dial the senza luce e colore prestito personali catania usb sd fm cuffie con radio integrata fm lancia y 2001 elezioni europei taj mahal salon de bahia galleon mix un medico in famiglia 5 inglesina emma paris (francia) di magia videoclip smackdown scarpe onitsuka hp 4p hp toner cd peter gabriel cercasi trans gran turismo 4 in musica viva la pappa col pomodoro stivali collant notebook masterizzatore dvd interno ati radeon 9600 da 256mb 256bit sito sms gratis il motomondiale turbo xt multi tap ps2 wild dance mpe e per te morellino di scansano brandl johann kierra knightly pentax obiettivo il solitario del west babol puzle la finta giardiniera mirabassi telecamera antifurto wireless crea corpi traduzione moondance ufficio delle entrate foto amatoriali di donne spogliate v9999 td 128mb modelli excel di contabilita bergamotti gps nemerix wierni memphis bells senza scampo playstation joystick soap opera confermato il ritorno di indiana jones nel 2007 delibes miguel bertolazzi carlo xevo caccia anatre cieli azzuri pupo amore s scale alluminio deca channel tv rivenditori calabria philips cordless 311 lets go straight lampada da testa decorare torta enola gay calcio a tre microsoft visual basic la donna quale animale si scopa ricette per cucinare il pavone myimmortal mid is it cos i m cod trimone champions league risultati ita siena lacie hard disk divx casting gf5 pioneer dcs 535 opel vectra 25 v6 24v 4p sport renato zero l equilibrista lebrecht danilo auto noleggio faenza powerbook apple sd wi fi silvio gigli lexus rx 400 fighette vergini nokia 5125 porno en dibujos bocelli vivo per lei finanziamento piccola impresa villaggio spagna fellowship benediro il signore traduzione i don t want you bach playstation console ps2 ohne dich rammstein racconti di sesso con i cavalli photo eminem inizio scuole canon mvx 300 scarafaggi before you acuse me scuola di liuteria keynes john neville esecuzione ostaggi ronald reagan bluetooth mini keyboard jeanette hold the line dvd film gratis pajas i vinti lavaggio auto iceberg effusion panasonic nv gs22 forem copertina cd hit mania dance 2006 actua tennis wwww sms it cuore uno zingaro mamma di un angelo webcam live pro piera una demo per airport tycoon 2 decoder usb pc tv plasma 42 phs ubanghi wwww mappy com brother 210c concerto pfm monza premi tesi billinger richard fermata per dodici ore justine una relazione privata wawes of luv midi 2 black alicebusiness it ricette di verdure navigatori car gps eos 1ds canon abbigliamento uomo energie racconti porno gay stampanti hp laserjet 2550n collane vetro hockey ice dvd 1 4gb instant video graz cose fare mobile cristallo plasma furness overlap vfa bleh matrox rtx10 yasmine bleeth nuda cecilia finotti iriver ifp squadra francese nuda harjai pontignano siena lesbianas asus a7n8xla bebe confort iseos stai con meu inglese corso giochi calcio pc garou esmeralda batteria sony t630 paco de lucia light and shade nikon mh53 marlyn manson cosmetico prodotti bellezza gran turismo 4 potrebbe ritardare anche in usa leatherman wave mp3 128mb everybodies change kings panasonic scpm21 dvd rw esterno firewire vampire the masquerade bloodlines video dell attentato in america dell 11 senza far rumore libera professione foto berry white volkswagen golf 1600 monitor lcd dvi 19 liviu vasilica misurini www movilnet com emp 30 dedicato a una stella hotel caesar nuevas normas de trafico due di raf mac speaker e cuffie procedure delle asl testo canzone aicha in italiano tram elenco rivenditori fossil toscana duplex un appartamento per tre week end a parigi athlete il portiere di notte enrico ruggeri o c soundtrack srl studio consulenza tributaria e del lavoro roma fotos di donas colombianas calendari george clooney jennifer hawkins nude kate rose codici tps sviluppa numeri superenalotto macchina per il pane delonghi desiderando giulia ubuntu e ti amo tariffa notaio frasi di ringraziamento per lutto gioco sony ericsson p800 la notte della taranta cd dvd tutto quello che un uomo puo fare jimny suzuki jonni dorelli codice magnum i cavalieri del drago giorgio vanni jeff stryker www gta vice city it
![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:
2000
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