Sum of first n cubes: Difference between revisions
Added Easylang
Not a robot (talk | contribs) (Add CLU) |
(Added Easylang) |
||
(22 intermediate revisions by 16 users not shown) | |||
Line 4:
Find and show sum of first '''n''' cubes, where '''n < 50''' (ie show 50 entries for n=0..49)
<br><br>
=={{header|11l}}==
{{trans|Nim}}
<syntaxhighlight lang="11l">V s = 0
L(n) 50
s += n * n * n
print(String(s).rjust(7), end' I (n + 1) % 10 == 0 {"\n"} E ‘ ’)</syntaxhighlight>
{{out}}
<pre>
0 1 9 36 100 225 441 784 1296 2025
3025 4356 6084 8281 11025 14400 18496 23409 29241 36100
44100 53361 64009 76176 90000 105625 123201 142884 164836 189225
216225 246016 278784 314721 354025 396900 443556 494209 549081 608400
672400 741321 815409 894916 980100 1071225 1168561 1272384 1382976 1500625
</pre>
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<syntaxhighlight lang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
PROC Main()
BYTE i
REAL sum,r3,tmp1,tmp2
Put(125) PutE() ;clear the screen
IntToReal(0,sum)
IntToReal(3,r3)
FOR i=0 TO 49
DO
IntToReal(i,tmp1)
RealMult(tmp1,tmp1,tmp2)
RealMult(tmp1,tmp2,tmp2)
RealAdd(sum,tmp2,sum)
PrintR(sum) Put(32)
IF i MOD 4=3 THEN
PutE()
FI
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sum_of_first_n_cubes.png Screenshot from Atari 8-bit computer]
<pre>
0 1 9 36 100 225 441 784 1296 2025 3025 4356
6084 8281 11025 14400 18496 23409 29241 36100
44100 53361 64009 76176 90000 105625 123201 142884
164836 189225 216225 246016 278784 314721 354025 396900
443556 494209 549081 608400 672400 741321 815409 894916
980100 1071225 1168561 1272384 1382976 1500625
</pre>
=={{header|Ada}}==
<
procedure Sum_Of_First_N_Cubes is
Line 26 ⟶ 77:
end loop;
New_Line;
end Sum_Of_First_N_Cubes;</
{{out}}
<pre>
Line 38 ⟶ 89:
=={{header|ALGOL 68}}==
As noted in the second factor example, the sum of the cubes to n is (n(n + 1))/2)^2, i.e. the square of the sum of the numbers to n.
<
FOR i FROM 0 TO 49 DO
INT sum = ( i * ( i + 1 ) ) OVER 2;
print( ( whole( sum * sum, -8 ) ) );
IF i MOD 10 = 9 THEN print( ( newline ) ) FI
OD</
{{out}}
<pre>
Line 54 ⟶ 105:
=={{header|ALGOL W}}==
<
integer cubeSum;
cubeSum := 0;
Line 62 ⟶ 113:
if n rem 10 = 9 then write()
end for_n
end.</
{{out}}
<pre>
Line 73 ⟶ 124:
=={{header|APL}}==
<
{{out}}
<pre> 0 1 9 36 100
Line 86 ⟶ 137:
1071225 1168561 1272384 1382976 1500625</pre>
=={{header|AppleScript}}==
<
-- sumsOfFirstNCubes :: Int -> [Int]
Line 297 ⟶ 348:
set my text item delimiters to dlm
return s
end unwords</
{{Out}}
<pre> 0 1 9 36 100
Line 312 ⟶ 363:
=={{header|Arturo}}==
<
loop split.every: 10 map 0..49 => [sumCubes: <= sumCubes + & ^ 3] 'a ->
print map a => [pad to :string & 7]</
{{out}}
Line 325 ⟶ 376:
=={{header|AutoHotkey}}==
<
loop 50 {
n := SubStr(" " ((A_Index-1)**3 + pn), -6)
Line 331 ⟶ 382:
pn := n
}
MsgBox % result</
{{out}}
<pre> 0 1 9 36 100 225 441 784 1296 2025
Line 340 ⟶ 391:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f SUM_OF_FIRST_N_CUBES.AWK
BEGIN {
Line 352 ⟶ 403:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 367 ⟶ 418:
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic256">
fila = 0
lenCubos = 49
Line 387 ⟶ 438:
print chr(13) + "Encontrados " & fila & " cubos."
end
</syntaxhighlight>
==={{header|FreeBASIC}}===
<
Dim As Integer fila = 0, lenCubos = 49, sumCubos
Line 409 ⟶ 460:
Print !"\nEncontrados " & fila & " cubos."
Sleep
</syntaxhighlight>
{{out}}
<pre>
Line 429 ⟶ 480:
==={{header|GW-BASIC}}===
<
20 C#=C#+N^3
30 PRINT C#;
40 NEXT N</
{{out}}<pre> 0 1 9 36 100 225 441 784 1296 2025 3025 4356 6084 8281 11025 14400 1
8496 23409 29241 36100 44100 53361 64009 76176 90000 105625 123201 142884
Line 440 ⟶ 491:
==={{header|QB64}}===
<
c& = c& + n%% ^ 3
Print Using " ####### "; c&;
If n%% Mod 5 = 4 Then Print
Next n%%</
{{out}}
<pre>
Line 461 ⟶ 512:
==={{header|QBasic}}===
{{trans|FreeBASIC}}
<
fila = 0
Line 480 ⟶ 531:
PRINT CHR$(13) + "Encontrados"; fila; "cubos."
END</
==={{header|Tiny BASIC}}===
{{works with|TinyBasic}}
Limited to 0 through 19 because integers only go up to 32767.
<
20 LET N = 0
30 LET C = C + N*N*N
Line 490 ⟶ 542:
50 LET N = N + 1
60 IF N = 19 THEN END
70 GOTO 30</
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">
fila = 0
lenCubos = 49
Line 513 ⟶ 565:
print "\nEncontrados ", fila, " cubos.\n"
end
</syntaxhighlight>
=={{header|BQN}}==
<syntaxhighlight lang
{{out}}
<pre>┌─
Line 532 ⟶ 584:
=={{header|C}}==
<
int main() {
Line 540 ⟶ 592:
}
return 0;
}</
{{out}}
Line 558 ⟶ 610:
=={{header|C#|CSharp}}==
No multiplication or exponentiation, just addition.
<
class Program { static void Main(string[] args) {
for (int i=0,j=-6,k=1,c=0,s=0;s<1600000;s+=c+=k+=j+=6)
Write("{0,-7}{1}",s, (i+=i==3?-4:1)==0?"\n":" "); } }</
{{out}}
<pre>0 1 9 36 100
Line 575 ⟶ 627:
=={{header|C++}}==
<
#include <cstdio>
#include <numeric>
Line 602 ⟶ 654:
std::transform_inclusive_scan(a.begin(), a.end(), a.begin(), std::plus{}, cube);
PrintContainer(a);
}</
{{out}}
<pre>
Line 613 ⟶ 665:
=={{header|CLU}}==
<
amount = 50
po: stream := stream$primary_output()
Line 623 ⟶ 675:
if i//5 = 4 then stream$putc(po, '\n') end
end
end start_up</
{{out}}
<pre> 0 1 9 36 100
Line 637 ⟶ 689:
=={{header|COBOL}}==
<
PROGRAM-ID. SUM-OF-CUBES.
Line 666 ⟶ 718:
IF OUT-PTR IS EQUAL TO 41,
DISPLAY OUT-LINE,
MOVE 1 TO OUT-PTR.</
{{out}}
<pre> 0 1 9 36 100
Line 678 ⟶ 730:
672400 741321 815409 894916 980100
1071225 1168561 1272384 1382976 1500625</pre>
=={{header|Comal}}==
<syntaxhighlight lang="comal">0010 ZONE 8
0020 sum:=0
0030 FOR cube:=0 TO 49 DO
0040 sum:+cube^3
0050 PRINT sum,
0060 IF cube MOD 5=4 THEN PRINT
0070 ENDFOR cube
0080 END</syntaxhighlight>
{{out}}
<pre>0 1 9 36 100
225 441 784 1296 2025
3025 4356 6084 8281 11025
14400 18496 23409 29241 36100
44100 53361 64009 76176 90000
105625 123201 142884 164836 189225
216225 246016 278784 314721 354025
396900 443556 494209 549081 608400
672400 741321 815409 894916 980100
1071225 1168561 1272384 1382976 1500625</pre>
=={{header|Cowgol}}==
<
sub cube(n: uint32): (r: uint32) is
Line 697 ⟶ 770:
print_char(' ');
end if;
end loop;</
{{out}}
<pre>0 1 9 36 100 225 441 784 1296 2025
Line 704 ⟶ 777:
216225 246016 278784 314721 354025 396900 443556 494209 549081 608400
672400 741321 815409 894916 980100 1071225 1168561 1272384 1382976 1500625</pre>
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
<syntaxhighlight lang="Delphi">
procedure ShowSumFirst50Cubes(Memo: TMemo);
var I,Sum: integer;
var S: string;
begin
S:='';
Sum:=0;
for I:=0 to 50-1 do
begin
Sum:=Sum+I*I*I;
S:=S+Format('%11.0n',[Sum+0.0]);
if (I mod 5)=4 then S:=S+CRLF;
end;
Memo.Lines.Add(S);
end;
</syntaxhighlight>
{{out}}
<pre>
0 1 9 36 100
225 441 784 1,296 2,025
3,025 4,356 6,084 8,281 11,025
14,400 18,496 23,409 29,241 36,100
44,100 53,361 64,009 76,176 90,000
105,625 123,201 142,884 164,836 189,225
216,225 246,016 278,784 314,721 354,025
396,900 443,556 494,209 549,081 608,400
672,400 741,321 815,409 894,916 980,100
1,071,225 1,168,561 1,272,384 1,382,976 1,500,625
Elapsed Time: 1.428 ms.
</pre>
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec cube(ulong n) ulong:
n * n * n
corp
proc nonrec main() void:
ulong sum;
byte n;
sum := 0;
for n from 0 upto 49 do
sum := sum + cube(n);
write(sum:8);
if n % 5 = 4 then writeln() fi
od
corp</syntaxhighlight>
{{out}}
<pre> 0 1 9 36 100
225 441 784 1296 2025
3025 4356 6084 8281 11025
14400 18496 23409 29241 36100
44100 53361 64009 76176 90000
105625 123201 142884 164836 189225
216225 246016 278784 314721 354025
396900 443556 494209 549081 608400
672400 741321 815409 894916 980100
1071225 1168561 1272384 1382976 1500625</pre>
=={{header|EasyLang}}==
<syntaxhighlight>
for i = 0 to 49
sum += i * i * i
write sum & " "
.
</syntaxhighlight>
=={{header|Excel}}==
Line 713 ⟶ 864:
{{Works with|Office 365 betas 2021}}
<
=LAMBDA(n,
BINCOEFF(1 + n)(2) ^ 2
Line 726 ⟶ 877:
)
)
)</
The single formula in cell B2 below defines a dynamic array which populates the whole B2:K6 grid:
Line 819 ⟶ 970:
=={{header|F_Sharp|F#}}==
<
// Sum of cubes: Nigel Galloway. May 20th., 2021
let fN g=g*g*g in Seq.initInfinite((+)1>>fN)|>Seq.take 49|>Seq.scan((+))(0)|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
{{out}}
<pre>
Line 830 ⟶ 981:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<
50 <iota> 0 [ 3 ^ + ] accumulate* 10 group simple-table.</
{{out}}
<pre>
Line 847 ⟶ 998:
{{works with|Factor|0.99 2021-02-05}}
<
: triangular ( n -- m ) dup 1 + * 2/ ;
50 <iota> [ triangular sq ] map 10 group simple-table.</
{{out}}
As above.
=={{header|Fermat}}==
<
for n = 0 to 49 do
c:=c+n^3;
!(c,' ');
od;</
{{out}}<pre> 0 1 9 36 100 225 441 784 1296 2025 3025 4356 6084 8281 11025 14400 18496 23409 29241 36100 44100 53361 64009 76176 90000 105625 123201 142884 164836 189225 216225 246016 278784 314721 354025 396900 443556 494209 549081 608400 672400 741321 815409 894916 980100 1071225 1168561 1272384 1382976 1500625</pre>
=={{header|Forth}}==
{{works with|Gforth}}
<
0 swap 0 do
i i i * * + dup 7 .r
Line 872 ⟶ 1,023:
50 sum-cubes
bye</
{{out}}
Line 886 ⟶ 1,037:
672400 741321 815409 894916 980100
1071225 1168561 1272384 1382976 1500625
</pre>
=={{header|Frink}}==
<syntaxhighlight lang="frink">sum = 0
result = new array
for n = 0 to 49
{
sum = sum + n^3
result.push[sum]
}
println[formatTable[columnize[result, 10], "right"]]</syntaxhighlight>
{{out}}
<pre>
0 1 9 36 100 225 441 784 1296 2025
3025 4356 6084 8281 11025 14400 18496 23409 29241 36100
44100 53361 64009 76176 90000 105625 123201 142884 164836 189225
216225 246016 278784 314721 354025 396900 443556 494209 549081 608400
672400 741321 815409 894916 980100 1071225 1168561 1272384 1382976 1500625
</pre>
Line 891 ⟶ 1,061:
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 909 ⟶ 1,079:
}
fmt.Println()
</syntaxhighlight>
{{out}}
Line 922 ⟶ 1,092:
=={{header|Haskell}}==
<
import Data.List.Split (chunksOf)
import Text.Printf (printf)
Line 963 ⟶ 1,133:
let ws = maximum . fmap length <$> transpose rows
pw = printf . flip intercalate ["%", "s"] . show
in unlines $ intercalate gap . zipWith pw ws <$> rows</
{{Out}}
<pre> 0 1 9 36 100 225 441 784 1296 2025
Line 973 ⟶ 1,143:
Or, in terms of scanl:
<
import Data.List.Split (chunksOf)
import Text.Printf (printf)
Line 982 ⟶ 1,152:
sumsOfFirstNCubes n =
scanl
(\a
0
[1 .. pred n]
Line 998 ⟶ 1,168:
let ws = maximum . fmap length <$> transpose rows
pw = printf . flip intercalate ["%", "s"] . show
in unlines $ intercalate gap . zipWith pw ws <$> rows</
{{Out}}
<pre> 0 1 9 36 100
Line 1,012 ⟶ 1,182:
=={{header|J}}==
<
{{out}}
<pre> 0 1 9 36 100
Line 1,024 ⟶ 1,194:
672400 741321 815409 894916 980100
1071225 1168561 1272384 1382976 1500625</pre>
If we wanted specifically the sum of positive integer cubes up through <code>n</code> it should be faster to use <code>0 0 1r4 1r2 1r4&p.</code>. For example:<syntaxhighlight lang="j"> 0 0 1r4 1r2 1r4&p. 49
1500625</syntaxhighlight>
=={{header|JavaScript}}==
<
"use strict";
Line 1,126 ⟶ 1,299:
s.padStart(n, c)
) : "";
Line 1,152 ⟶ 1,312:
const
colWidths = transpose(rows).map(
row =>
...row.map(x => x.length)
)
);
Line 1,209 ⟶ 1,371:
// MAIN ---
return main();
})();</
{{Out}}
<pre> 0 1 9 36 100
Line 1,225 ⟶ 1,387:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">
# For the sake of stream-processing efficiency:
def add(s): reduce s as $x (0; . + $x);
def sum_of_cubes: add(range(0;.) | .*.*.);</
'''The task'''
<syntaxhighlight lang="jq">
range(0;50) | sum_of_cubes as $sum
| "\(.) => \($sum)"</
{{out}}
<pre>
Line 1,255 ⟶ 1,417:
=={{header|Julia}}==
<
cubesumstil()
</
<pre>
0 1 9 36 100 225 441 784 1296 2025
Line 1,267 ⟶ 1,429:
</pre>
Alternatively, and using the REPL, note that recent versions of Julia implement the accumulate function:
<
julia> println(accumulate((x, y) -> x + y^3, 0:49))
[0, 1, 9, 36, 100, 225, 441, 784, 1296, 2025, 3025, 4356, 6084, 8281, 11025, 14400, 18496, 23409, 29241, 36100, 44100, 53361, 64009, 76176, 90000, 105625, 123201, 142884, 164836, 189225, 216225, 246016, 278784, 314721, 354025, 396900, 443556, 494209, 549081, 608400, 672400, 741321, 815409, 894916, 980100, 1071225, 1168561, 1272384, 1382976, 1500625]
</syntaxhighlight>
=={{header|K}}==
{{works with|ngn/k}}<syntaxhighlight lang=K>5 10#+\{x*x*x}[!50]
(0 1 9 36 100 225 441 784 1296 2025
3025 4356 6084 8281 11025 14400 18496 23409 29241 36100
44100 53361 64009 76176 90000 105625 123201 142884 164836 189225
216225 246016 278784 314721 354025 396900 443556 494209 549081 608400
672400 741321 815409 894916 980100 1071225 1168561 1272384 1382976 1500625)</syntaxhighlight>
=={{header|MAD}}==
<
SUM = 0
THROUGH LOOP, FOR STEP = 0, 1, STEP.GE.50
Line 1,280 ⟶ 1,450:
LOOP PRINT FORMAT FMT, SUM
VECTOR VALUES FMT = $I9*$
END OF PROGRAM </
{{out}}
<pre style='height:50ex;'> 0
Line 1,334 ⟶ 1,504:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
{{out}}
<pre>{0,1,9,36,100,225,441,784,1296,2025,3025,4356,6084,8281,11025,14400,18496,23409,29241,36100,44100,53361,64009,76176,90000,105625,123201,142884,164836,189225,216225,246016,278784,314721,354025,396900,443556,494209,549081,608400,672400,741321,815409,894916,980100,1071225,1168561,1272384,1382976,1500625}</pre>
=={{header|Nim}}==
<
var s = 0
for n in 0..49:
s += n * n * n
stdout.write ($s).align(7), if (n + 1) mod 10 == 0: '\n' else: ' '</
{{out}}
Line 1,354 ⟶ 1,524:
=={{header|PARI/GP}}==
<
=={{header|Pascal}}==
<syntaxhighlight lang="pascal">program sumOfFirstNCubes(output);
const
N = 49;
var
i: integer;
sum: integer;
begin
sum := 0;
for i := 0 to N do
begin
sum := sum + sqr(i) * i;
{ In Extended Pascal you could also write:
sum := sum + i pow 3; }
writeLn(sum)
end
end.</syntaxhighlight>
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/Sum_of_first_n_cubes
Line 1,363 ⟶ 1,551:
my $sum = 0;
printf "%10d%s", $sum += $_ ** 3, $_ % 5 == 4 && "\n" for 0 .. 49;</
{{out}}
<pre>
Line 1,380 ⟶ 1,568:
=={{header|Phix}}==
The commented out line is based on the Factor entry, and is clearly a much faster way to get the same results.
<!--<
<span style="color: #008080;">function</span> <span style="color: #000000;">sum_first_n_cubes</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sq_power</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">),</span><span style="color: #000000;">3</span><span style="color: #0000FF;">))</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #000080;font-style:italic;">--function sum_first_n_cubes(integer n) return power(n*(n+1)/2,2) end function</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">49</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">),</span><span style="color: #000000;">sum_first_n_cubes</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%,9d"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">res</span><span style="color: #0000FF;">}),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)})</span>
<!--</
{{out}}
<pre>
Line 1,396 ⟶ 1,584:
=={{header|PILOT}}==
<
:n=0
:max=50
Line 1,405 ⟶ 1,593:
T :#n: #sum
J (n<max):*loop
E :</
{{out}}
<pre style='height:50ex;'>1: 0
Line 1,459 ⟶ 1,647:
=={{header|Plain English}}==
<
Start up.
Show the sums of cubes given 49.
Line 1,472 ⟶ 1,660:
Write the result then " " on the console without advancing.
If the counter is evenly divisible by 5, write "" on the console.
Repeat.</
{{out}}
<pre>
Line 1,488 ⟶ 1,676:
=={{header|PL/I}}==
<
declare (i, csum) fixed decimal(7);
csum = 0;
Line 1,496 ⟶ 1,684:
if mod(i,5) = 4 then put skip;
end;
end cubeSum;</
{{out}}
<pre> 0 1 9 36 100
Line 1,511 ⟶ 1,699:
=={{header|PL/M}}==
The original 8080 PL/M compiler only supported 8 and 16 bit unsigned arithmetic, so this sample only shows the sums < 65536.
<
/* CP/M BDOS SYSTEM CALL */
Line 1,541 ⟶ 1,729:
END;
EOF</
{{out}}
<pre>
Line 1,552 ⟶ 1,740:
===Python :: Procedural===
{{trans|FreeBASIC}}
<
def main():
fila = 0
Line 1,572 ⟶ 1,760:
if __name__ == '__main__': main()
</syntaxhighlight>
{{out}}
<pre>
Line 1,593 ⟶ 1,781:
===Python :: Functional===
<
from math import factorial
Line 1,663 ⟶ 1,851:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre> 0 1 9 36 100 225 441 784 1296 2025
Line 1,674 ⟶ 1,862:
or, as a scanning accumulation:
<
from itertools import accumulate
Line 1,732 ⟶ 1,920:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre> 0 1 9 36 100
Line 1,747 ⟶ 1,935:
=={{header|Quackery}}==
<
50 times
[ i^ 3 ** +
Line 1,754 ⟶ 1,942:
space join ] ]
drop
nest$ 65 wrap$</
{{out}}
Line 1,767 ⟶ 1,955:
=={{header|R}}==
This only takes one line.
<syntaxhighlight lang
{{out}}
<pre> [1] 0 1 9 36 100 225 441 784 1296 2025 3025 4356 6084 8281 11025 14400
Line 1,775 ⟶ 1,963:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
say .fmt('%7d') for @sums_of_all_cubes.head(50).batch(10);</
{{out}}
<pre>
Line 1,785 ⟶ 1,973:
216225 246016 278784 314721 354025 396900 443556 494209 549081 608400
672400 741321 815409 894916 980100 1071225 1168561 1272384 1382976 1500625
</pre>
=={{header|Red}}==
<syntaxhighlight lang="rebol">Red ["Sum of cubes"]
sum: 0
repeat i 50 [
sum: i - 1 ** 3 + sum
prin pad sum 8
if i % 10 = 0 [prin newline]
]</syntaxhighlight>
{{out}}
<pre>
0 1 9 36 100 225 441 784 1296 2025
3025 4356 6084 8281 11025 14400 18496 23409 29241 36100
44100 53361 64009 76176 90000 105625 123201 142884 164836 189225
216225 246016 278784 314721 354025 396900 443556 494209 549081 608400
672400 741321 815409 894916 980100 1071225 1168561 1272384 1382976 1500625
</pre>
=={{header|REXX}}==
<
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 50 /*Not specified? Then use the default.*/
Line 1,813 ⟶ 2,019:
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</
{{out|output|text= when using the default inputs:}}
(Shown at five-sixth size.)
Line 1,831 ⟶ 2,037:
=={{header|Ring}}==
<
see "working..." + nl
see "Sum of first n cubes:" + nl
Line 1,851 ⟶ 2,057:
see "Found " + row + " cubes" + nl
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 1,869 ⟶ 2,075:
done...
</pre>
=={{header|RPL}}==
≪ { } 0 0 49 '''FOR''' n n 3 ^ + SWAP OVER + SWAP '''NEXT''' DROP ≫ EVAL
{{out}}
<pre>
1: { 0 1 9 36 100 225 441 784 1296 2025 3025 4356 6084 8281 11025 14400 18496 23409 29241 36100 44100 53361 64009 76176 90000 105625 123201 142884 164836 189225 216225 246016 278784 314721 354025 396900 443556 494209 549081 608400 672400 741321 815409 894916 980100 1071225 1168561 1272384 1382976 1500625 }
</pre>
===Direct calculation===
≪ DUP 1 + * 2 / SQ ≫ ''''∑CUBE'''' STO
49 '''∑CUBE'''
{{out}}
<pre>
1: 1500625
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">sum = 0
(0...50).each do |n|
print (sum += n**3).to_s.ljust(10)
puts "" if (n+1) % 10 == 0
end
</syntaxhighlight>
{{out}}
<pre>0 1 9 36 100 225 441 784 1296 2025
3025 4356 6084 8281 11025 14400 18496 23409 29241 36100
44100 53361 64009 76176 90000 105625 123201 142884 164836 189225
216225 246016 278784 314721 354025 396900 443556 494209 549081 608400
672400 741321 815409 894916 980100 1071225 1168561 1272384 1382976 1500625 </pre>
=={{header|Rust}}==
<
(0..50)
.scan(0, |sum, x| {
Line 1,886 ⟶ 2,120:
}
});
}</
{{out}}
Line 1,903 ⟶ 2,137:
=={{header|Seed7}}==
<
const proc: main is func
Line 1,915 ⟶ 2,149:
end if;
end for;
end func;</
{{out}}
<pre>
Line 1,930 ⟶ 2,164:
</pre>
=={{header|SETL}}==
<syntaxhighlight lang="setl">program sum_of_first_cubes;
cubes := [n**3 : n in [0..49]];
loop for i in [2..#cubes] do
cubes(i) +:= cubes(i-1);
end loop;
printtab(cubes, 5, 10);
proc printtab(list, cols, width);
lines := [list(k..cols+k-1) : k in [1, cols+1..#list]];
loop for line in lines do
print(+/[lpad(str item, width+1) : item in line]);
end loop;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre> 0 1 9 36 100
225 441 784 1296 2025
3025 4356 6084 8281 11025
14400 18496 23409 29241 36100
44100 53361 64009 76176 90000
105625 123201 142884 164836 189225
216225 246016 278784 314721 354025
396900 443556 494209 549081 608400
672400 741321 815409 894916 980100
1071225 1168561 1272384 1382976 1500625</pre>
=={{header|Sidef}}==
<
{{out}}
<pre>
Line 1,944 ⟶ 2,206:
672400 741321 815409 894916 980100
1071225 1168561 1272384 1382976 1500625
</pre>
=={{header|VTL-2}}==
Based on the TinyBASIC sample but with multiple sums per line and showing the first 23 values as VTL-2 has unsigned 16-bit integers.
<syntaxhighlight lang="vtl2">
10 C=0
20 N=0
30 C=N*N*N+C
40 ?=C
50 $=9
60 N=N+1
70 #=N/6*0+%>1*90
80 ?=""
90 #=N<23*30
</syntaxhighlight>
{{out}}
<pre>
0 1 9 36 100 225
441 784 1296 2025 3025 4356
6084 8281 11025 14400 18496 23409
29241 36100 44100 53361 64009
</pre>
=={{header|Wren}}==
<
System.print("Cumulative sums of the first 50 cubes:")
Line 1,956 ⟶ 2,239:
if ((n % 10) == 9) System.print()
}
System.print()</
{{out}}
Line 1,969 ⟶ 2,252:
=={{header|X86 Assembly}}==
<
2 0000 .model tiny
3 0000 .code
Line 2,027 ⟶ 2,310:
57 0156 C3 ret
58
59 end start</
{{out}}
Line 2,044 ⟶ 2,327:
=={{header|XPL0}}==
<
[S:= 0;
for N:= 0 to 49 do
Line 2,052 ⟶ 2,335:
if rem(N/5) = 4 then CrLf(0);
];
]</
{{out}}
Line 2,069 ⟶ 2,352:
=={{header|Zig}}==
<
const stdout = @import("std").io.getStdOut().writer();
Line 2,080 ⟶ 2,363:
if (i % 5 == 4) try stdout.print("\n", .{});
}
}</
{{out}}
<pre> 0 1 9 36 100
|