Sum of first n cubes: Difference between revisions

Added Easylang
m (syntax highlighting fixup automation)
(Added Easylang)
 
(9 intermediate revisions by 9 users not shown)
Line 534:
 
==={{header|Tiny BASIC}}===
{{works with|TinyBasic}}
Limited to 0 through 19 because integers only go up to 32767.
<syntaxhighlight lang="tinybasicbasic">10 LET C = 0
20 LET N = 0
30 LET C = C + N*N*N
Line 776 ⟶ 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}}==
Line 803 ⟶ 847:
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 985 ⟶ 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 1,363 ⟶ 1,434:
[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}}==
Line 1,996 ⟶ 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}}==
Line 2,057 ⟶ 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}}==
<syntaxhighlight lang="ruby">0..49 -> map { .faulhaber_sum(3) }.slices(5).each { .join(' ').say }</syntaxhighlight>
Line 2,071 ⟶ 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}}==
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
System.print("Cumulative sums of the first 50 cubes:")
2,043

edits