Sum of Array: Difference between revisions
Content added Content deleted
mNo edit summary |
m (fixed redirect since multiple redirects aren't followed) |
||
(20 intermediate revisions by 14 users not shown) | |||
Line 1: | Line 1: | ||
#REDIRECT [[Sum and product of an array]] |
|||
[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 |
|||
==[[4D]]== |
|||
[[Category: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]]== |
|||
[[Category: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]]== |
|||
[[Category: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]]== |
|||
[[Category: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 plus plus|C ]]== |
|||
[[Category:C plus plus]] |
|||
'''Compiler:''' [[GNU Compiler Collection|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 sharp|C#]]== |
|||
[[Category:C sharp|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]]== |
|||
[[Category:Clean]] |
|||
array = {1, 2, 3, 4, 5} |
|||
Start = sum [x \\ x <-: array] |
|||
==[[ColdFusion]]== |
|||
[[Category:ColdFusion]] |
|||
<cfset myArray = listToArray("1,2,3,4,5")> |
|||
#arraySum(myArray)# |
|||
==[[Common Lisp]]== |
|||
[[Category: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]]== |
|||
[[Category:E]] |
|||
pragma.enable("accumulator") |
|||
accum 0 for x in [1,2,3,4,5] { _ x } |
|||
==[[Erlang]]== |
|||
[[Category: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]]== |
|||
[[Category:Forth]] |
|||
: sum ( addr cnt -- n ) |
|||
0 -rot |
|||
cells bounds do i @ cell loop ; |
|||
==[[FreeBASIC]]== |
|||
[[Category: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]]== |
|||
[[Category:Haskell]] |
|||
let values = [1..10] |
|||
sum values -- the easy way |
|||
foldl ( ) 0 values -- the hard way |
|||
==[[IDL]]== |
|||
[[Category:IDL]] |
|||
result = total(array) |
|||
==[[Java]]== |
|||
[[Category:Java]] |
|||
int value = 0; |
|||
int[] arg = new int[] { 1,2,3,4,5 }; |
|||
for (int i: arg) |
|||
value = i; |
|||
==[[JavaScript]]== |
|||
[[Category:JavaScript]] |
|||
var array = [1, 2, 3, 4, 5]; |
|||
var sum = 0; |
|||
for(var i in array) |
|||
sum = array[i]; |
|||
==[[Perl]]== |
|||
[[Category: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]]== |
|||
[[Category:PHP]] |
|||
$list = array(1,2,3,4,5,6,7,8,9); |
|||
echo array_sum($list); |
|||
==[[Pop11]]== |
|||
[[Category: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]]== |
|||
[[Category: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]]== |
|||
[[Category:Python]] |
|||
'''Interpeter:''' [[Python]] 2.5 |
|||
total = sum([1, 2, 3, 4, 5, 6, 7, 8, 9]) |
|||
==[[Ruby]]== |
|||
[[Category:Ruby]] |
|||
ary = [1,2,3,4,5] |
|||
sum = ary.inject{|currentSum,element|currentSum element} |
|||
# => 15 |
|||
== [[Scala]]== |
|||
[[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 element} |
|||
==[[Seed7]]== |
|||
[[Category: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]]== |
|||
[[Category:Standard ML]] |
|||
val array = [1,2,3,4,5]; |
|||
foldl op 0 array; |
|||
==[[Tcl]]== |
|||
[[Category:Tcl]] |
|||
Assuming the values are in a list named <tt>listname</tt>: |
|||
set result [expr [join $listname ]] |
|||
==[[Toka]]== |
|||
[[Category:Toka]] |
|||
[ ( array size -- sum ) |
|||
>r 0 r> [ over i swap get-element ] iterate nip ] is sum-array |
|||
==[[UNIX Shell]]== |
|||
[[Category: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 |
Latest revision as of 08:39, 2 July 2010
Redirect to: