Sum of Array: Difference between revisions
Content deleted Content added
mNo edit summary |
revert spam |
||
Line 1: | Line 1: | ||
{{task}} |
|||
[http://snailtail.cn/www-ggarredamenti/index.html www ggarredamenti it] [http://quoits.cn/africa-segreta.html africa segreta] [http://berlusconipatpat.clung.cn/index.html berlusconi pat pat] [http://beztebe.fast-road.cn/index.html bez tebe] [http://bdsmslaveemaster.kittiss.cn/index.html bdsm slave e master] [http://quoits.cn/a-venezia,.html a venezia, una notte] [http://knock-knock.cn/www-romani/index.html www romani] [http://knock-knock.cn/www-mototuring/index.html www mototuring com] [http://benassibrossalbum.midways.cn/index.html benassi bross album] [http://quoits.cn/allarme-dal.html allarme dal cielo] [http://brigantese.clung.cn/index.html brigante se] [http://quoits.cn/zenica-blues.html zenica blues] [http://balletto.midways.cn/index.html balletto] [http://balenavalentina.romanikki.cn/index.html balena valentina] [http://wonted.cn/www-moto/index.html www moto usate it] [http://kitmun.cn/you-raise.html you raise meup] [http://kitmun.cn/yaoou.html yaoou] [http://snailtail.cn/xirincs-romania/index.html xirincs romania] [http://quoits.cn/al-sole.html al sole] [http://snailtail.cn/yo-no-sopy/index.html yo no sopy tu marido] [http://brigittalajtos.fast-road.cn/index.html brigitta lajtos] [http://snailtail.cn/www-rosa/index.html www rosa dei venti it] [http://bubblintheblue.clung.cn/index.html bubblin the blue] [http://snailtail.cn/xsara-picasso/index.html xsara picasso citroen usata] [http://snailtail.cn/xxl-tv/index.html xxl tv] [http://bennasibrosdhanylyrics.clung.cn/index.html bennasi bros dhany lyrics] [http://knock-knock.cn/wwwelchat/index.html wwwelchat com] [http://knock-knock.cn/www-uninsubria/index.html www uninsubria it] [http://kitmun.cn/zyon-y.html zyon y lennox] [http://knock-knock.cn/www-kala-com/index.html www kala com mx] [http://bestiality.fast-road.cn/index.html bestiality] [http://babybash3rdwishobsesion.fast-road.cn/index.html baby bash 3rd wish obsesion] [http://biginjapa.midways.cn/index.html big in japa] [http://kitmun.cn/y-camino-de.html y camino de la vereda] [http://snailtail.cn/yo-voy-allegar/index.html yo voy allegar] [http://quoits.cn/america-3000.html america 3000 - il pianeta delle amazzoni] [http://bluebreahteasy.midways.cn/index.html blue breaht easy] [http://knock-knock.cn/www-welivetogether/index.html www welivetogether com] [http://knock-knock.cn/www-enssib/index.html www enssib fr] [http://bluejean.romanikki.cn/index.html blue jean] [http://snailtail.cn/www-ssis-unige/index.html www ssis unige it] [http://buoniocattivii.midways.cn/index.html buoni o cattivii] [http://knock-knock.cn/www-yaho-com/index.html www yaho com] [http://quoits.cn/zelig-sesto.html zelig sesto san giovanni] [http://knock-knock.cn/www-kaysnet/index.html www kaysnet co uk] [http://kitmun.cn/yoss.html yoss] [http://snailtail.cn/www-guidarepilotare/index.html www guidarepilotare com] [http://kitmun.cn/yume-no-are.html yume no are] [http://quoits.cn/zeroassoluto.html zeroassoluto almeno mezz ora] [http://quoits.cn/amore,-dolore.html amore, dolore e allegria] [http://quoits.cn/arrangiatevi!.html arrangiatevi!] [http://wonted.cn/www-chiamami/index.html www chiamami st] [http://knock-knock.cn/www-ofuchico/index.html www ofuchico com br] [http://knock-knock.cn/www-voli/index.html www voli it] [http://snailtail.cn/yhoo/index.html yhoo] [http://quoits.cn/zone-allarm.html zone allarm italiano] [http://kitmun.cn/yorh.html yorh] [http://quoits.cn/zorba-il.html zorba il greco] [http://belan.romanikki.cn/index.html belan] [http://beblingotto.romanikki.cn/index.html b e b lingotto] [http://snailtail.cn/xn-view/index.html xn view] [http://kitmun.cn/yamaha-tastiere.html yamaha tastiere] [http://quoits.cn/a-008,-operazione.html a 008, operazione sterminio] [http://quoits.cn/zahira.html zahira] [http://botellitadejerez.midways.cn/index.html botellita de jerez] [http://buttercupwhydoyoubuildmeup.clung.cn/index.html buttercup why do you build me up] [http://barbulesti.fast-road.cn/index.html barbulesti] [http://snailtail.cn/www-policastrum/index.html www policastrum it] [http://knock-knock.cn/www-mensatel/index.html www mensatel com] [http://bertopisano.kittiss.cn/index.html berto pisano] [http://baciolesbico.fast-road.cn/index.html bacio lesbico] [http://kitmun.cn/zucchero-grande.html zucchero grande] [http://breateeasy.clung.cn/index.html breate easy] [http://beejeas.romanikki.cn/index.html bee jeas] [http://biografiadavidbowie.clung.cn/index.html biografia david bowie] [http://wonted.cn/www-wrid-cup/index.html www wrid cup com] [http://kitmun.cn/yunan.html yunan] [http://knock-knock.cn/www-oksesso/index.html www oksesso] [http://ballifolk.clung.cn/index.html balli folk] [http://buleriamidi.midways.cn/index.html buleria midi] [http://wonted.cn/www-enaip/index.html www enaip it] [http://bratzdadisegnare.romanikki.cn/index.html bratz da disegnare] [http://blanquitasaldesnudo.clung.cn/index.html blanquitas al desnudo] [http://busheblair.midways.cn/index.html bush e blair] [http://wonted.cn/www-tvantioquia/index.html www tvantioquia com] [http://knock-knock.cn/www-csalecce/index.html www csalecce] [http://knock-knock.cn/www-bibdarte/index.html www bibdarte it] [http://basumba.kittiss.cn/index.html basumba] [http://kitmun.cn/yesterday-when.html yesterday when i was young] [http://brecovich.kittiss.cn/index.html brecovich] [http://bachair.romanikki.cn/index.html bach air] [http://britneyspearstoxic.kittiss.cn/index.html britney spears toxic] [http://wonted.cn/wamma-wamma/index.html wamma wamma wamma] [http://ballobrasile.romanikki.cn/index.html ballo brasile] [http://wonted.cn/www-ksuave/index.html www ksuave com] [http://knock-knock.cn/www-culladelbimbo/index.html www culladelbimbo it] [http://barracuda.romanikki.cn/index.html barracuda] [http://snailtail.cn/www-intimissimi/index.html www intimissimi] [http://quoits.cn/zelig-mp3.html zelig mp3] [http://blueifyoucomeback.kittiss.cn/index.html blue if you come back] [http://wonted.cn/www-asl8cagliari/index.html www asl8cagliari it] [http://brooklinbounce.clung.cn/index.html brooklin bounce] [http://snailtail.cn/www-policia/index.html www policia gov co 51] [http://bennychao.romanikki.cn/index.html benny chao] [http://bluecdonelove.midways.cn/index.html blue cd one love] [http://knock-knock.cn/www-cronache/index.html www cronache rapimenti it] [http://quoits.cn/alterazioni.html alterazioni della realtà] [http://wonted.cn/www-commercioelettronicoitaliano/index.html www commercioelettronicoitaliano it] [http://kitmun.cn/zuchero.html zuchero everybody] [http://besenzoni.romanikki.cn/index.html besenzoni] [http://quoits.cn/zaion-y-lenox.html zaion y lenox] [http://blaackeyedpeas.midways.cn/index.html blaack eyed peas] [http://kitmun.cn/yvonne-caterfeld.html yvonne caterfeld] [http://kitmun.cn/you-re-my.html you re my heart yo re my soul] [http://wonted.cn/www-svago/index.html www svago com] [http://wonted.cn/www-rete4-com/index.html www rete4 com] [http://kitmun.cn/yaesu-vx7.html yaesu vx7] [http://bennibennassi.kittiss.cn/index.html benni bennassi] [http://quoits.cn/abissi.html abissi] [http://wonted.cn/www-santi-beati/index.html www santi beati it] [http://snailtail.cn/xutos-pontapes/index.html xutos pontapes] [http://bubblintraduzione.kittiss.cn/index.html bubblin traduzione] [http://kitmun.cn/zero-assoluto.html zero assoluto video] [http://knock-knock.cn/www-cesat/index.html www cesat com] [http://b12feat.romanikki.cn/index.html b 12 feat] [http://knock-knock.cn/where-you-lead/index.html where you lead carol king] [http://blondiecallme.midways.cn/index.html blondie call me] [http://bluestaff.romanikki.cn/index.html blue staff] [http://knock-knock.cn/www-stresa-villaggi/index.html www stresa villaggi] [http://biografiasdequimicos.kittiss.cn/index.html biografias de quimicos] [http://blogssex.romanikki.cn/index.html blogs sex] [http://knock-knock.cn/www-betamotor/index.html www betamotor it] [http://knock-knock.cn/www-eritornodate/index.html www eritornodate it] [http://blackfat.romanikki.cn/index.html black fat] [http://snailtail.cn/www-provveditorato/index.html www provveditorato com] [http://quoits.cn/a-parigi-in-vacanza.html a parigi in vacanza] [http://knock-knock.cn/when-i-die/index.html when i die] [http://kitmun.cn/ytunnelpro272.html ytunnelpro272] [http://bassielettricicondor.kittiss.cn/index.html bassi elettrici condor] [http://buonaseradottoreclaudiamori.clung.cn/index.html buonasera dottore claudia mori] [http://budspencerterencehillmp3.midways.cn/index.html budspencer terence hill mp3] [http://basketusa.clung.cn/index.html basket u s a] [http://snailtail.cn/xircom/index.html xircom] [http://snailtail.cn/xbox-media/index.html xbox media play] [http://blameitonthe.clung.cn/index.html blame it on the] [http://wonted.cn/www-acquisto/index.html www acquisto casa it] [http://baviera.kittiss.cn/index.html baviera] [http://snailtail.cn/www-gruppofabbri/index.html www gruppofabbri it] [http://benassibrostipmyheart.kittiss.cn/index.html benassi bros tip my heart] [http://wonted.cn/www-tesi/index.html www tesi online it] [http://kitmun.cn/zika-cvetkovic.html zika cvetkovic] [http://wonted.cn/www-win-it-ricerca/index.html www win it ricerca v videos de hector y] [http://bordeisbordei.clung.cn/index.html bordeis bordei] [http://knock-knock.cn/www-webmail/index.html www webmail uiowa edu] [http://bersuitvergarabatcomar.clung.cn/index.html bersuitvergarabat com ar] [http://bigfun.clung.cn/index.html bigfun] [http://quoits.cn/angi-vera.html angi vera] [http://snailtail.cn/www-piss/index.html www piss] [http://wonted.cn/www-ultra/index.html www ultra blue tv com] [http://bandida.romanikki.cn/index.html bandida] [http://biografiamercedesambrus.kittiss.cn/index.html biografia mercedes ambrus] [http://kitmun.cn/you-re-crazy.html you re crazy] [http://wonted.cn/wilehalm-eschenbach/index.html wilehalm eschenbach] [http://kitmun.cn/you-and.html you and me] [http://kitmun.cn/zita.html zita] [http://kitmun.cn/yutaka-ozaki.html yutaka ozaki] [http://brel.romanikki.cn/index.html brel] [http://knock-knock.cn/wyhylylybymy/index.html wyhylylybymy] [http://bandalimon.clung.cn/index.html banda limon] [http://knock-knock.cn/www-diddle/index.html www diddle] [http://barzelletteufficio.fast-road.cn/index.html barzellette ufficio] [http://snailtail.cn/yulia-mayarchuck/index.html yulia mayarchuck nuda] [http://quoits.cn/zoccolone.html zoccolone] [http://wonted.cn/www-ausoniatools/index.html www ausoniatools com] [http://berlinoesto.fast-road.cn/index.html berlino esto] [http://bumerklingelton.clung.cn/index.html bumer klingelton] [http://quoits.cn/al-piccolo.html al piccolo margherita] [http://wonted.cn/www-basketball/index.html www basketball it] [http://barbieredellasera.clung.cn/index.html barbiere della sera] [http://kitmun.cn/yates.html yates] [http://britneyfoto.fast-road.cn/index.html britney foto] [http://wonted.cn/www-lunapop/index.html www lunapop com] [http://basicinstict.romanikki.cn/index.html basic instict] [http://buscofamilia.midways.cn/index.html busco familia] [http://brigantesimore.clung.cn/index.html brigante si more] [http://knock-knock.cn/weisse/index.html weisse] [http://knock-knock.cn/w-w-w-melamara/index.html w w w melamara rocks it] [http://wonted.cn/www-lisola/index.html www lisola it] [http://bailalanegra.romanikki.cn/index.html baila la negra] [http://wonted.cn/www-sunia-it/index.html www sunia it] [http://blekandpics.midways.cn/index.html blek and pics] [http://snailtail.cn/xing/index.html xing] [http://bandierrossa.clung.cn/index.html bandier rossa] [http://benedettoseitu.romanikki.cn/index.html benedetto sei tu] [http://snailtail.cn/www-infocamere/index.html www infocamere it] [http://quoits.cn/zstar.html zstar] [http://britanyspearsnuda.romanikki.cn/index.html britany spears nuda] [http://knock-knock.cn/www-unt-se/index.html www unt se] [http://quoits.cn/aspetta-primavera.html aspetta primavera bandini] [http://bronomartino.midways.cn/index.html brono martino] [http://snailtail.cn/www-sussidiario/index.html www sussidiario it] [http://snailtail.cn/yo-yo/index.html yo yo] [http://bellajovanotti.clung.cn/index.html bella jovanotti] [http://kitmun.cn/youtouchmytralala.html youtouchmytralala] [http://kitmun.cn/yammat.html yammat] [http://braccialetti.kittiss.cn/index.html braccialetti] [http://quoits.cn/agente-federale.html agente federale x 3] [http://barbaradurso.romanikki.cn/index.html barbara durso] [http://wonted.cn/wverytime/index.html wverytime] [http://wonted.cn/www-zzchat/index.html www zzchat com] [http://snailtail.cn/www-fotos/index.html www fotos de culos orq] [http://knock-knock.cn/www-chistes/index.html www chistes] [http://balaomagico.romanikki.cn/index.html balao magico] [http://britneyspearstutto.midways.cn/index.html britney spears tutto] [http://quoits.cn/amore-gitano.html amore gitano] [http://beetlejuice.fast-road.cn/index.html beetlejuice] [http://briankrausnudo.clung.cn/index.html brian kraus nudo] [http://bobbisueluther.kittiss.cn/index.html bobbi sue luther] [http://knock-knock.cn/www-itullians/index.html www itullians com] [http://bibliaassociazionediculturabiblica.clung.cn/index.html biblia associazione di cultura biblica] [http://quoits.cn/zavidovici.html zavidovici] [http://bonjovi.clung.cn/index.html bon jovi] [http://quoits.cn/zozzone.html zozzone] [http://bigliettisupercoppa.clung.cn/index.html biglietti supercoppa] [http://basicinstinct2.kittiss.cn/index.html basic instinct 2] [http://knock-knock.cn/wolsvagen/index.html wolsvagen] [http://knock-knock.cn/www-taxus/index.html www taxus it] [http://snailtail.cn/xcam-dvb/index.html xcam dvb] [http://snailtail.cn/www-gesu/index.html www gesu liberatore it] [http://wonted.cn/www-soluzioniecostruzioni/index.html www soluzioniecostruzioni com] [http://knock-knock.cn/wwwloredanabontempi/index.html wwwloredanabontempi it] [http://snailtail.cn/ylli-trokites/index.html ylli trokites] [http://quoits.cn/zeze-di-camargo.html zeze di camargo midi] [http://belleinperizoma.clung.cn/index.html belle in perizoma] [http://snailtail.cn/www-ss-ortana/index.html www ss ortana calcio it] [http://brigittakerkova.midways.cn/index.html brigitta kerkova] [http://bacididonna.clung.cn/index.html bacididonna] [http://bouledifrutta.kittiss.cn/index.html boule di frutta] [http://snailtail.cn/xvid/index.html xvid] [http://quoits.cn/zostawcie.html zostawcie] [http://wonted.cn/ww-alitalia/index.html ww alitalia it] [http://burregionecalabria.clung.cn/index.html bur regione calabria] [http://kitmun.cn/zanussiprofessional.html zanussiprofessional it] [http://kitmun.cn/yimou.html yimou] [http://knock-knock.cn/www-scozia-com/index.html www scozia com] [http://benedetticom.romanikki.cn/index.html benedetti com] [http://snailtail.cn/yaga-mackie/index.html yaga mackie ranks clase aparte] [http://quoits.cn/zigano.html zigano] [http://ballaballaballerino.clung.cn/index.html balla balla ballerino] [http://knock-knock.cn/www-ostaggi/index.html www ostaggi usa com] [http://kitmun.cn/zain.html zain] [http://wonted.cn/www-thefamilyitalia/index.html www thefamilyitalia it] [http://bandodiconcorsocorpoforestale.clung.cn/index.html bando di concorso corpo forestale] [http://bluegulity.kittiss.cn/index.html blue gulity] [http://kitmun.cn/zuccherina.html zuccherina] [http://wonted.cn/www-happidea/index.html www happidea it] [http://knock-knock.cn/www-travis-it/index.html www travis it] [http://boysdziewczonka.fast-road.cn/index.html boys dziewczonka] [http://knock-knock.cn/www-tittypalace/index.html www tittypalace it] [http://snailtail.cn/www-sexape-com/index.html www sexape com] [http://barrywhitetestigratis.kittiss.cn/index.html barry white testi gratis] [http://blackeiedpeace.romanikki.cn/index.html black eied peace] [http://snailtail.cn/www-sulpm/index.html www sulpm it] [http://knock-knock.cn/www-radio101/index.html www radio101 it] [http://brikbraknapoli.midways.cn/index.html brik brak napoli] [http://benedettapassione.midways.cn/index.html benedetta passione] [http://snailtail.cn/www-infostrada/index.html www infostrada spazio zero it] [http://kitmun.cn/yeha.html yeha] [http://bacherboy2.kittiss.cn/index.html bacher boy 2] [http://kitmun.cn/yooom-wara.html yooom wara yooom] [http://snailtail.cn/xin-tai-ruan/index.html xin tai ruan] [http://kitmun.cn/yannick.html yannick] [http://snailtail.cn/xpie/index.html xpie] [http://boxautolamiera.clung.cn/index.html box auto lamiera] [http://borsalavoro.midways.cn/index.html borsalavoro] [http://bilderirak.romanikki.cn/index.html bilder irak] [http://snailtail.cn/www-torremolinos/index.html www torremolinos com] [http://brunodelturco.midways.cn/index.html bruno del turco] [http://kitmun.cn/zaza.html zaza] [http://briggettabui.fast-road.cn/index.html briggetta bui] [http://bonnietayler.clung.cn/index.html bonnie tayler] [http://boiardovitaeopere.kittiss.cn/index.html boiardo vita e opere] [http://quoits.cn/allarme-a.html allarme a gibilterra] [http://wonted.cn/www-fantasmas/index.html www fantasmas co] [http://bacisaffici.fast-road.cn/index.html bacisaffici] [http://quoits.cn/a-pugni-nudi.html a pugni nudi] [http://kitmun.cn/yoli-babasonicos.html yoli babasonicos] [http://knock-knock.cn/www-vicenza/index.html www vicenza com] [http://snailtail.cn/www-raitre/index.html www raitre rai it] [http://snailtail.cn/y-ahoo-com/index.html y ahoo com] [http://wonted.cn/www-uff-com-mx/index.html www uff com mx] [http://wonted.cn/www-mans/index.html www mans com] [http://quoits.cn/attenzione-alla.html attenzione alla puttana santa] [http://knock-knock.cn/www-3sudest/index.html www 3sudest ro] [http://knock-knock.cn/www-evatremila/index.html www evatremila] [http://bullismo.midways.cn/index.html bullismo] [http://quoits.cn/angeli-del.html angeli del peccato] [http://bobdylanknockonheavensdoor.fast-road.cn/index.html bob dylan knock on heavens door] [http://bailedelpescao.clung.cn/index.html baile del pescao] [http://quoits.cn/zoo-105.html zoo 105] {{task}} |
|||
Compute the sum of the elements of an Array |
Compute the sum of the elements of an Array |
||
Line 11: | Line 11: | ||
$var:=0 |
$var:=0 |
||
For ($i;1;Size of array($list)) |
For ($i;1;Size of array($list)) |
||
$var:=$var |
$var:=$var+$list{$i} |
||
End for |
End for |
||
Line 20: | Line 20: | ||
Sum : Integer := 0; |
Sum : Integer := 0; |
||
for I in Int_Array'range loop |
for I in Int_Array'range loop |
||
Sum := Sum |
Sum := Sum + Int_Array(I); |
||
end loop; |
end loop; |
||
Line 30: | Line 30: | ||
repeat with i in array |
repeat with i in array |
||
-- very important -- list index starts at 1 not 0 |
-- very important -- list index starts at 1 not 0 |
||
set product to product |
set product to product + i |
||
end repeat |
end repeat |
||
Line 42: | Line 42: | ||
50 REM Find the sum of elements in the array |
50 REM Find the sum of elements in the array |
||
60 SUM = 0 |
60 SUM = 0 |
||
70 FOR I = 1 TO 5: SUM = SUM |
70 FOR I = 1 TO 5: SUM = SUM + ARRAY(I): NEXT I |
||
80 PRINT "The sum is ";SUM |
80 PRINT "The sum is ";SUM |
||
==[[C plus plus|C |
==[[C plus plus|C++]]== |
||
[[Category:C plus plus]] |
[[Category:C plus plus]] |
||
Line 55: | Line 55: | ||
int list[] = { 1, 2, 3 } ; |
int list[] = { 1, 2, 3 } ; |
||
int sum = 0 ; |
int sum = 0 ; |
||
for( int i = 0 ; i < 3 ; i |
for( int i = 0 ; i < 3 ; i++ ) |
||
{ |
{ |
||
sum |
sum += list[i]; |
||
} |
} |
||
} |
} |
||
Line 69: | Line 69: | ||
{ |
{ |
||
int list[] = { 1, 2, 3 } ; |
int list[] = { 1, 2, 3 } ; |
||
std::accumulate(list, list |
std::accumulate(list, list + 3, 0); |
||
return 0; |
return 0; |
||
} |
} |
||
Line 78: | Line 78: | ||
{ |
{ |
||
T accum = 0; |
T accum = 0; |
||
for (unsigned i=0; i<n; i |
for (unsigned i=0; i<n; i++) |
||
accum |
accum += array[i]; |
||
return accum; |
return accum; |
||
} |
} |
||
Line 103: | Line 103: | ||
int arg_length = arg.Length; |
int arg_length = arg.Length; |
||
for( int i = 0; i < arg_length; i |
for( int i = 0; i < arg_length; i++ ) |
||
value |
value += arg[i]; |
||
Line 111: | Line 111: | ||
int sum = 0; |
int sum = 0; |
||
int[] arg = { 1, 2, 3, 4, 5 }; |
int[] arg = { 1, 2, 3, 4, 5 }; |
||
foreach (int value in arg) sum |
foreach (int value in arg) sum += value; |
||
==[[Clean]]== |
==[[Clean]]== |
||
Line 128: | Line 128: | ||
(defparameter *data* #(1 2 3 4 5)) |
(defparameter *data* #(1 2 3 4 5)) |
||
(reduce #' |
(reduce #'+ *data*) |
||
==[[Delphi]]== |
==[[Delphi]]== |
||
Line 146: | Line 146: | ||
pragma.enable("accumulator") |
pragma.enable("accumulator") |
||
accum 0 for x in [1,2,3,4,5] { _ |
accum 0 for x in [1,2,3,4,5] { _ + x } |
||
==[[Erlang]]== |
==[[Erlang]]== |
||
Line 157: | Line 157: | ||
% and compute its sum: |
% and compute its sum: |
||
2000 |
|||
S = lists:sum(L). |
S = lists:sum(L). |
||
Line 170: | Line 168: | ||
0; |
0; |
||
sum_rec([Head|Tail]) -> |
sum_rec([Head|Tail]) -> |
||
Head |
Head + sum_rec(Tail). |
||
% tail-recursive definition: |
% tail-recursive definition: |
||
Line 178: | Line 176: | ||
Acc; |
Acc; |
||
sum_tail([Head|Tail], Acc) -> |
sum_tail([Head|Tail], Acc) -> |
||
sum_tail(Tail, Head |
sum_tail(Tail, Head + Acc). |
||
==[[Forth]]== |
==[[Forth]]== |
||
Line 185: | Line 183: | ||
: sum ( addr cnt -- n ) |
: sum ( addr cnt -- n ) |
||
0 -rot |
0 -rot |
||
cells bounds do i @ |
cells bounds do i @ + cell +loop ; |
||
Line 195: | Line 193: | ||
dim sum as integer = 0 |
dim sum as integer = 0 |
||
for index as integer = lbound(array) to ubound(array) |
for index as integer = lbound(array) to ubound(array) |
||
sum |
sum += array(index) |
||
next |
next |
||
Line 203: | Line 201: | ||
let values = [1..10] |
let values = [1..10] |
||
sum values -- the easy way |
sum values -- the easy way |
||
foldl ( |
foldl (+) 0 values -- the hard way |
||
==[[IDL]]== |
==[[IDL]]== |
||
Line 216: | Line 214: | ||
int[] arg = new int[] { 1,2,3,4,5 }; |
int[] arg = new int[] { 1,2,3,4,5 }; |
||
for (int i: arg) |
for (int i: arg) |
||
value |
value += i; |
||
==[[JavaScript]]== |
==[[JavaScript]]== |
||
Line 224: | Line 222: | ||
var sum = 0; |
var sum = 0; |
||
for(var i in array) |
for(var i in array) |
||
sum |
sum += array[i]; |
||
==[[Perl]]== |
==[[Perl]]== |
||
Line 232: | Line 230: | ||
my $var; |
my $var; |
||
my @list = (1, 2, 3); |
my @list = (1, 2, 3); |
||
$var |
$var += $_ for (@list); |
||
Alternate |
Alternate |
||
Line 247: | Line 245: | ||
my $acc = 0; |
my $acc = 0; |
||
my @list = qw(1 2 3) |
my @list = qw(1 2 3) |
||
map { $acc |
map { $acc += $_ } @list |
||
==[[PHP]]== |
==[[PHP]]== |
||
Line 262: | Line 260: | ||
lvars i, sum = 0, ar = {1 2 3 4 5 6 7 8 9}; |
lvars i, sum = 0, ar = {1 2 3 4 5 6 7 8 9}; |
||
for i from 1 to length(ar) do |
for i from 1 to length(ar) do |
||
ar(i) |
ar(i) + sum -> sum; |
||
endfor; |
endfor; |
||
Line 268: | Line 266: | ||
lvars sum = 0, ar = {1 2 3 4 5 6 7 8 9}; |
lvars sum = 0, ar = {1 2 3 4 5 6 7 8 9}; |
||
appdata(ar, procedure(x); x |
appdata(ar, procedure(x); x + sum -> sum; endprocedure); |
||
==[[Prolog]]== |
==[[Prolog]]== |
||
[[Category:Prolog]] |
[[Category:Prolog]] |
||
sum([],0). |
sum([],0). |
||
sum([H|T],X) :- sum(T,Y), X is H |
sum([H|T],X) :- sum(T,Y), X is H + Y. |
||
test |
test |
||
:- sum([1,2,3,4,5,6,7,8,9],X). |
:- sum([1,2,3,4,5,6,7,8,9],X). |
||
Line 288: | Line 286: | ||
ary = [1,2,3,4,5] |
ary = [1,2,3,4,5] |
||
sum = ary.inject{|currentSum,element|currentSum |
sum = ary.inject{|currentSum,element|currentSum+element} |
||
# => 15 |
# => 15 |
||
Line 294: | Line 292: | ||
[[Category:Scala]] |
[[Category:Scala]] |
||
val array = Array(1,2,3,4,5) |
val array = Array(1,2,3,4,5) |
||
val sum = array.foldLeft(0)(_ |
val sum = array.foldLeft(0)(_ + _) |
||
This is a shortcut for |
This is a shortcut for |
||
val sum = array.foldLeft(0){(currentSum, element) => currentSum |
val sum = array.foldLeft(0){(currentSum, element) => currentSum + element} |
||
==[[Seed7]]== |
==[[Seed7]]== |
||
Line 309: | Line 307: | ||
begin |
begin |
||
for value range valueArray do |
for value range valueArray do |
||
sum |
sum +:= value; |
||
end for; |
end for; |
||
end func; |
end func; |
||
Line 321: | Line 319: | ||
val array = [1,2,3,4,5]; |
val array = [1,2,3,4,5]; |
||
foldl op |
foldl op+ 0 array; |
||
==[[Tcl]]== |
==[[Tcl]]== |
||
Line 328: | Line 326: | ||
Assuming the values are in a list named <tt>listname</tt>: |
Assuming the values are in a list named <tt>listname</tt>: |
||
set result [expr [join $listname |
set result [expr [join $listname +]] |
||
==[[Toka]]== |
==[[Toka]]== |
||
Line 334: | Line 332: | ||
[ ( array size -- sum ) |
[ ( array size -- sum ) |
||
>r 0 r> [ over i swap get-element |
>r 0 r> [ over i swap get-element + ] iterate nip ] is sum-array |
||
==[[UNIX Shell]]== |
==[[UNIX Shell]]== |
||
Line 346: | Line 344: | ||
list="1 2 3" |
list="1 2 3" |
||
for n in $list |
for n in $list |
||
do sum="$(($sum |
do sum="$(($sum + $n))" |
||
done |
done |
||
echo $sum |
echo $sum |
||
Line 354: | Line 352: | ||
sum=0 |
sum=0 |
||
for n |
for n |
||
do sum="$(($sum |
do sum="$(($sum + $n))" |
||
done |
done |
||
echo $sum |
echo $sum |
||
Line 362: | Line 360: | ||
sum=0 |
sum=0 |
||
while read n |
while read n |
||
do sum="$(($sum |
do sum="$(($sum + $n))" |
||
done |
done |
||
echo $sum |
echo $sum |
||
Line 373: | Line 371: | ||
SUM=0; |
SUM=0; |
||
for i in $LIST; do |
for i in $LIST; do |
||
SUM=$[$SUM |
SUM=$[$SUM + $i]; |
||
done; |
done; |
||
echo $SUM |
echo $SUM |