Sum of Array: Difference between revisions
Content deleted Content added
revert spam |
mNo edit summary |
||
Line 1: | Line 1: | ||
[http://stbrocke.125mb.com/content/lettore-dvd.htm lettore dvd divx dv380s] [http://kamedcal.125mb.com/sony-cuffie.htm sony cuffie 5 1] [http://mcgoley.125mb.com/articles/audi-noleggio.htm audi noleggio] [http://mamerium.125mb.com/marzia.htm marzia] [http://bakedsmurf.ifrance.com/description/dinasty/ dinasty] [http://sylverrain.ifrance.com/data/hombres-sexys/ hombres sexys] [http://dragonzgrace.ifrance.com/description/pico-zip/ pico2000 zip] [http://prkinardan.125mb.com/styles/gigi-and.htm gigi and molly] [http://kamedcal.125mb.com/www-match.htm www match com] [http://prkinardan.125mb.com/styles/avana-shopping.htm avana shopping] [http://kuzelka111.ifrance.com/lib/beethoven-sonata/ beethoven sonata per violino e pianoforte] [http://sylverrain.ifrance.com/data/lift-me/ lift me up] [http://mcgoley.125mb.com/articles/telecamera-videosorveglianza.htm telecamera videosorveglianza] [http://mamerium.125mb.com/scheda-video.htm scheda video interfaccia pci] [http://superspounge.ifrance.com/the-mission/ the mission dancing on mars] [http://kuzelka111.ifrance.com/lib/lavorazioni-sul/ lavorazioni sul tornio in parallelo] [http://kewheatl.125mb.com/library/viaggi-in.htm viaggi in nave per la sardegna] [http://madavidan.125mb.com/text/mp-.htm mp3 128 fm] [http://bemedad.125mb.com/blog/gsmart-mini.htm gsmart mini] [http://earthlygnome.ifrance.com/sara-connor/ sara connor] [http://vanopo.ifrance.com/library/palmare-phone/ palmare phone edition] [http://mamerium.125mb.com/camera-commercio.htm camera commercio roma] [http://earthlygnome.ifrance.com/decollete-d/ decollete 3d] [http://prkinardan.125mb.com/styles/denni-fantina.htm denni fantina] [http://kewheatl.125mb.com/library/samsung-.htm samsung ps42d5s] [http://mcgoley.125mb.com/articles/madamigella-oscar.htm madamigella oscar] [http://madavidan.125mb.com/text/c-kit.htm c900 kit] [http://bemedad.125mb.com/blog/troia-che.htm troia che caga] [http://madavidan.125mb.com/text/toner-mfc.htm toner mfc7420] [http://earthlygnome.ifrance.com/dv-mustek/ dv mustek] [http://superspounge.ifrance.com/nec-ux/ nec 2180ux] [http://doloeb.125mb.com/outpost.htm outpost 2] [http://vanopo.ifrance.com/library/lettore-dvd/ lettore dvd divx nero] [http://prkinardan.125mb.com/styles/once-upon.htm once upon a time in mexico] [http://bemedad.125mb.com/blog/remi.htm remi] [http://madavidan.125mb.com/text/pendenti-breil.htm pendenti breil] [http://prkinardan.125mb.com/styles/immagine-mare.htm immagine mare] [http://kuzelka111.ifrance.com/lib/louisiana-ristorante/ louisiana ristorante] [http://madavidan.125mb.com/text/suzuki-alto.htm suzuki alto 1998] [http://mike12305.ifrance.com/lib/tribali-e/ tribali e tatuaggi] [http://earthlygnome.ifrance.com/kris-grove/ kris grove e kris reichert] [http://superspounge.ifrance.com/il-maresciallo/ il maresciallo rocca stagione 4 episodio 6] [http://mike12305.ifrance.com/lib/oselin/ oselin] [http://mcgoley.125mb.com/articles/km-fiat.htm km0 fiat panda gpl auto km 0] [http://dragonzgrace.ifrance.com/description/mujeres-blancas/ mujeres blancas] [http://sylverrain.ifrance.com/data/eight-wonder/ eight wonder] [http://dragonzgrace.ifrance.com/description/tv-acer/ tv acer] [http://bemedad.125mb.com/blog/drin-drin.htm drin drin a rispondi] [http://kamedcal.125mb.com/dolce-e.htm dolce e gabbana uomo maglieria] [http://todkonda.ifrance.com/content/sito-fotografia/ sito fotografia] [http://superspounge.ifrance.com/dogg/ dogg] [http://sylverrain.ifrance.com/data/il-cacciatore/ il cacciatore di alieni] [http://madavidan.125mb.com/text/www-sessomania.htm www sessomania com] [http://vanopo.ifrance.com/library/km-fiat/ km0 fiat panda] [http://kuzelka111.ifrance.com/lib/ragazza-cassino/ ragazza cassino] [http://todkonda.ifrance.com/content/taglia-tubi/ taglia tubi] [http://superspounge.ifrance.com/intel-e/ intel e un processore tutto da giocare] [http://dragonzgrace.ifrance.com/description/giochi-carte/ giochi carte scopa] [http://mamerium.125mb.com/foto-di.htm foto di londra] [http://bakedsmurf.ifrance.com/description/hp/ hp 8200] [http://kuzelka111.ifrance.com/lib/victor-ugo/ victor ugo] [http://mcgoley.125mb.com/articles/lo-sbaglio.htm lo sbaglio di essere vivo] [http://kewheatl.125mb.com/library/storia-guanto.htm storia guanto] [http://doloeb.125mb.com/dolce-e.htm dolce e gabbana jeans uomo] [http://mamerium.125mb.com/kingston-gb.htm kingston 1gb] [http://bemedad.125mb.com/blog/www-e.htm www e i it] [http://vanopo.ifrance.com/library/gioco-dei/ gioco dei conigli] [http://superspounge.ifrance.com/marx-it/ marx it] [http://prkinardan.125mb.com/styles/mfc-cn.htm mfc 3340cn] [http://kewheatl.125mb.com/library/campo-concentramento.htm campo concentramento] [http://earthlygnome.ifrance.com/test-medicina/ test medicina] [http://superspounge.ifrance.com/nortek/ nortek 2 1] [http://madavidan.125mb.com/text/napoli-donne.htm napoli donne] [http://bakedsmurf.ifrance.com/description/km-opel/ km0 opel meriva auto km 0] [http://sylverrain.ifrance.com/data/x-agosto/ x agosto pascoli] [http://madavidan.125mb.com/text/innamorato.htm innamorato] [http://kewheatl.125mb.com/library/ponzi.htm ponzi] [http://sylverrain.ifrance.com/data/sex/ sex0] [http://stbrocke.125mb.com/content/himno-nacional.htm himno nacional del per] [http://superspounge.ifrance.com/la-possibile/ la (possibile) data europea di gran turismo 4] [http://bakedsmurf.ifrance.com/description/di-marino/ di marino francesco] [http://superspounge.ifrance.com/sesso-sporco/ sesso sporco] [http://prkinardan.125mb.com/styles/cunbias.htm cunbias] [http://sylverrain.ifrance.com/data/carolina-gf/ carolina gf 4] [http://madavidan.125mb.com/text/vivavoce-per.htm vivavoce per v3 motorola] [http://kuzelka111.ifrance.com/lib/sauna-e/ sauna e massaggi] [http://madavidan.125mb.com/text/kazaa-ita.htm kazaa ita] [http://stbrocke.125mb.com/content/cdv.htm cdv] [http://todkonda.ifrance.com/content/che-figata/ che figata di serata] [http://mike12305.ifrance.com/lib/francks/ francks] [http://dragonzgrace.ifrance.com/description/tylko-ty/ tylko ty kaja paschalska] [http://superspounge.ifrance.com/gif-animate/ gif animate bandiera] [http://mamerium.125mb.com/the-moon.htm the moon italian version] [http://kamedcal.125mb.com/midnight-invaders.htm midnight invaders] [http://bakedsmurf.ifrance.com/description/upa-dance/ upa dance sambame] [http://earthlygnome.ifrance.com/salento-in/ salento in bus] [http://sylverrain.ifrance.com/data/ospedale-gaslini/ ospedale gaslini] [http://raneely.125mb.com/text/timothy-zahn.htm timothy zahn] [http://prkinardan.125mb.com/styles/crack-nec.htm crack nec e 228] [http://raneely.125mb.com/text/miriam-preziosi.htm miriam preziosi srl] [http://dragonzgrace.ifrance.com/description/winamp-full/ winamp5 full final] [http://kamedcal.125mb.com/pegao.htm pegao] [http://kewheatl.125mb.com/library/antenna-magnetica.htm antenna magnetica] [http://dragonzgrace.ifrance.com/description/causa-di/ causa di divorzio] [http://sylverrain.ifrance.com/data/outlook-/ outlook 2000 software] [http://kamedcal.125mb.com/in-partibus.htm in partibus infidelium] [http://superspounge.ifrance.com/underdog/ underdog] [http://mcgoley.125mb.com/articles/pesca-tropea.htm pesca tropea] [http://mcgoley.125mb.com/articles/philips-bcs.htm philips 190b6cs] [http://mcgoley.125mb.com/articles/armband-ipod.htm armband ipod] [http://raneely.125mb.com/text/musica-house.htm musica house kama kama] [http://mike12305.ifrance.com/lib/bigazzi-giancarlo/ bigazzi giancarlo] [http://stbrocke.125mb.com/content/screensaver-paesaggio.htm screensaver paesaggio] [http://madavidan.125mb.com/text/sera-de.htm sera de dios erreway] [http://vanopo.ifrance.com/library/filmati-gay/ filmati gay samples] [http://stbrocke.125mb.com/content/quando-soffia.htm quando soffia il vento del nord] [http://kamedcal.125mb.com/www-concorsi.htm www concorsi cinofili it] [http://bakedsmurf.ifrance.com/description/enriko/ enriko] [http://superspounge.ifrance.com/maray/ maray] [http://bemedad.125mb.com/blog/fugo.htm fugo] [http://mamerium.125mb.com/inovix-imp.htm inovix imp10] [http://mamerium.125mb.com/lumix-fz.htm lumix fz30] [http://stbrocke.125mb.com/content/college-loan.htm college loan] [http://mike12305.ifrance.com/lib/starcraft-fotos/ starcraft fotos] [http://kuzelka111.ifrance.com/lib/accessori-qtek/ accessori qtek 9090] [http://mamerium.125mb.com/emule-c.htm emule 46c gratuito] [http://raneely.125mb.com/text/microsoft-volante.htm microsoft volante] [http://mamerium.125mb.com/foto-da.htm foto da film] [http://kuzelka111.ifrance.com/lib/foto-di/ foto di palme] [http://mike12305.ifrance.com/lib/prima-station/ prima station wagon con vintage] [http://raneely.125mb.com/text/dragos-team.htm dragos team] [http://sylverrain.ifrance.com/data/ti-porto/ ti porto in africa mango] [http://stbrocke.125mb.com/content/garbahaarey.htm garbahaarey] [http://mamerium.125mb.com/tommy-boy.htm tommy boy] [http://kamedcal.125mb.com/chance-di.htm chance di chanel] [http://dragonzgrace.ifrance.com/description/tatarsk/ tatarsk] [http://earthlygnome.ifrance.com/prodotti-lavazza/ prodotti lavazza] [http://bemedad.125mb.com/blog/gilet-sport.htm gilet sport] [http://bakedsmurf.ifrance.com/description/ragazze-in/ ragazze in cam] [http://raneely.125mb.com/text/la-ragazza.htm la ragazza del golden saloon] [http://mamerium.125mb.com/testina-stanton.htm testina stanton] [http://bemedad.125mb.com/blog/bic-ruga.htm bic ruga] [http://kamedcal.125mb.com/televisore-philips.htm televisore philips 21] [http://dragonzgrace.ifrance.com/description/marisa-monte/ marisa monte ao vivo] [http://mamerium.125mb.com/final-fighter.htm final fighter] [http://kamedcal.125mb.com/giochi-da.htm giochi da scaricare per cellulare 3] [http://mcgoley.125mb.com/articles/midnight-sugar.htm midnight sugar] [http://bakedsmurf.ifrance.com/description/il-commissario/ il commissario maigret il pazzo di bergerac] [http://earthlygnome.ifrance.com/masterizzatore-dvd/ masterizzatore dvd pc] [http://raneely.125mb.com/text/barcellona-p.htm barcellona p g] [http://kewheatl.125mb.com/library/hoogle.htm hoogle] [http://sylverrain.ifrance.com/data/kyosho-subaru/ kyosho subaru] [http://bemedad.125mb.com/blog/proietti-cavaliere.htm proietti cavaliere nero] [http://vanopo.ifrance.com/library/memoria-pc/ memoria pc100] [http://dragonzgrace.ifrance.com/description/horse-fucking/ horse fucking] [http://superspounge.ifrance.com/giochi/ giochi 2] [http://vanopo.ifrance.com/library/motorola-auricolare/ motorola auricolare bluethoot] [http://earthlygnome.ifrance.com/televisori-al/ televisori al plasma 42 xga] [http://vanopo.ifrance.com/library/coa/ coa] [http://doloeb.125mb.com/rose-red.htm rose red di stephen king] [http://superspounge.ifrance.com/paolo-gentili/ paolo gentili] [http://stbrocke.125mb.com/content/benzin.htm benzin] [http://bemedad.125mb.com/blog/mehsana.htm mehsana] [http://bakedsmurf.ifrance.com/description/kartika/ kartika] [http://prkinardan.125mb.com/styles/nardi.htm nardi] [http://mike12305.ifrance.com/lib/pointless/ pointless] [http://doloeb.125mb.com/adattatore-lenti.htm adattatore lenti canon] [http://raneely.125mb.com/text/seagate-barracuda.htm seagate barracuda 7200 7 200gb] [http://kuzelka111.ifrance.com/lib/celebration/ celebration] [http://madavidan.125mb.com/text/lincoln-gran.htm lincoln (gran bretagna)] [http://mike12305.ifrance.com/lib/testa-decapitata/ testa decapitata] [http://mcgoley.125mb.com/articles/mi-sono.htm mi sono depilata] [http://sylverrain.ifrance.com/data/dmr/ dmr3] [http://vanopo.ifrance.com/library/rubinetti-per/ rubinetti per lavabo] [http://kewheatl.125mb.com/library/logos.htm logos 584] [http://raneely.125mb.com/text/riss.htm riss] [http://kewheatl.125mb.com/library/scheda-usb.htm scheda usb2 pci] [http://doloeb.125mb.com/hotail-com.htm hotail com] [http://mamerium.125mb.com/parodie.htm parodie 2004] [http://mcgoley.125mb.com/articles/uiguri.htm uiguri] [http://doloeb.125mb.com/masterizzatore-dvd.htm masterizzatore dvd mac] [http://kamedcal.125mb.com/volkswagen-polo.htm volkswagen polo 1 9 tdi] [http://sylverrain.ifrance.com/data/di-tanti/ di tanti palpiti] [http://earthlygnome.ifrance.com/film-erotici/ film erotici] [http://stbrocke.125mb.com/content/erogatore-pesca.htm erogatore pesca] [http://madavidan.125mb.com/text/life-is.htm life is] [http://todkonda.ifrance.com/content/the-devil/ the devil kiss] [http://kewheatl.125mb.com/library/fotocamera-digitale.htm fotocamera digitale yakumo mega image] [http://prkinardan.125mb.com/styles/bartolomeo-della.htm bartolomeo della gatta] [http://prkinardan.125mb.com/styles/ydra.htm ydra] [http://mike12305.ifrance.com/lib/molle/ molle] [http://sylverrain.ifrance.com/data/frigoriferi-combi/ frigoriferi combi da incasso rex] [http://mike12305.ifrance.com/lib/de-ce/ de ce] [http://stbrocke.125mb.com/content/francesca-duranti.htm francesca duranti] [http://mcgoley.125mb.com/articles/herrera.htm herrera 212] [http://earthlygnome.ifrance.com/psp-sony/ psp sony] [http://raneely.125mb.com/text/z.htm z4 30] [http://superspounge.ifrance.com/www-itunes/ www itunes store] [http://prkinardan.125mb.com/styles/black-knigh.htm black knigh] [http://bemedad.125mb.com/blog/sappur-suppur.htm sappur suppur] {{task}} |
|||
{{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 168: | Line 168: | ||
0; |
0; |
||
sum_rec([Head|Tail]) -> |
sum_rec([Head|Tail]) -> |
||
Head |
Head sum_rec(Tail). |
||
% tail-recursive definition: |
% tail-recursive definition: |
||
Line 176: | 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 183: | 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 193: | 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 201: | 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 214: | 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 222: | 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 230: | Line 230: | ||
my $var; |
my $var; |
||
my @list = (1, 2, 3); |
my @list = (1, 2, 3); |
||
$var |
$var = $_ for (@list); |
||
Alternate |
Alternate |
||
Line 245: | 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 260: | 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 266: | 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 286: | 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 292: | 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 307: | 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 319: | 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 326: | 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 332: | 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 344: | 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 352: | Line 352: | ||
sum=0 |
sum=0 |
||
for n |
for n |
||
do sum="$(($sum |
do sum="$(($sum $n))" |
||
done |
done |
||
echo $sum |
echo $sum |
||
Line 360: | 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 371: | 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 |