Jump to content

Sum of first n cubes: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 8:
{{trans|Nim}}
 
<langsyntaxhighlight 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 ‘ ’)</langsyntaxhighlight>
 
{{out}}
Line 24:
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
PROC Main()
Line 44:
FI
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sum_of_first_n_cubes.png Screenshot from Atari 8-bit computer]
Line 57:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io;
 
procedure Sum_Of_First_N_Cubes is
Line 77:
end loop;
New_Line;
end Sum_Of_First_N_Cubes;</langsyntaxhighlight>
{{out}}
<pre>
Line 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.
<langsyntaxhighlight lang="algol68"># show the sums of the first n cubes where 0 <= n < 50 #
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</langsyntaxhighlight>
{{out}}
<pre>
Line 105:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin % show the sums of the cubes of n for 0 <= n < 50 %
integer cubeSum;
cubeSum := 0;
Line 113:
if n rem 10 = 9 then write()
end for_n
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 124:
 
=={{header|APL}}==
<langsyntaxhighlight APLlang="apl">10 5⍴+\0,(⍳49)*3</langsyntaxhighlight>
{{out}}
<pre> 0 1 9 36 100
Line 137:
1071225 1168561 1272384 1382976 1500625</pre>
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">------------------- SUM OF FIRST N CUBES -----------------
 
-- sumsOfFirstNCubes :: Int -> [Int]
Line 348:
set my text item delimiters to dlm
return s
end unwords</langsyntaxhighlight>
{{Out}}
<pre> 0 1 9 36 100
Line 363:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">sumCubes: 0
loop split.every: 10 map 0..49 => [sumCubes: <= sumCubes + & ^ 3] 'a ->
print map a => [pad to :string & 7]</langsyntaxhighlight>
 
{{out}}
Line 376:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">pn := 0, result := ""
loop 50 {
n := SubStr(" " ((A_Index-1)**3 + pn), -6)
Line 382:
pn := n
}
MsgBox % result</langsyntaxhighlight>
{{out}}
<pre> 0 1 9 36 100 225 441 784 1296 2025
Line 391:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SUM_OF_FIRST_N_CUBES.AWK
BEGIN {
Line 403:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 418:
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic256">
<lang BASIC256>
fila = 0
lenCubos = 49
Line 438:
print chr(13) + "Encontrados " & fila & " cubos."
end
</syntaxhighlight>
</lang>
 
==={{header|FreeBASIC}}===
<langsyntaxhighlight lang="freebasic">
Dim As Integer fila = 0, lenCubos = 49, sumCubos
 
Line 460:
Print !"\nEncontrados " & fila & " cubos."
Sleep
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 480:
 
==={{header|GW-BASIC}}===
<langsyntaxhighlight lang="gwbasic">10 FOR N=0 TO 49
20 C#=C#+N^3
30 PRINT C#;
40 NEXT N</langsyntaxhighlight>
{{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 491:
 
==={{header|QB64}}===
<langsyntaxhighlight lang="qbasic">For n%% = 0 To 49
c& = c& + n%% ^ 3
Print Using " ####### "; c&;
If n%% Mod 5 = 4 Then Print
Next n%%</langsyntaxhighlight>
{{out}}
<pre>
Line 512:
==={{header|QBasic}}===
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="qbasic">DEFLNG A-Z
 
fila = 0
Line 531:
 
PRINT CHR$(13) + "Encontrados"; fila; "cubos."
END</langsyntaxhighlight>
 
==={{header|Tiny BASIC}}===
Limited to 0 through 19 because integers only go up to 32767.
<langsyntaxhighlight lang="tinybasic">10 LET C = 0
20 LET N = 0
30 LET C = C + N*N*N
Line 541:
50 LET N = N + 1
60 IF N = 19 THEN END
70 GOTO 30</langsyntaxhighlight>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">
<lang Yabasic>
fila = 0
lenCubos = 49
Line 564:
print "\nEncontrados ", fila, " cubos.\n"
end
</syntaxhighlight>
</lang>
 
=={{header|BQN}}==
<syntaxhighlight lang ="bqn">∘‿5⥊+`(↕50)⋆3</langsyntaxhighlight>
{{out}}
<pre>┌─
Line 583:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int main() {
Line 591:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 609:
=={{header|C#|CSharp}}==
No multiplication or exponentiation, just addition.
<langsyntaxhighlight lang="csharp">using System; using static System.Console;
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":" "); } }</langsyntaxhighlight>
{{out}}
<pre>0 1 9 36 100
Line 626:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <array>
#include <cstdio>
#include <numeric>
Line 653:
std::transform_inclusive_scan(a.begin(), a.end(), a.begin(), std::plus{}, cube);
PrintContainer(a);
}</langsyntaxhighlight>
{{out}}
<pre>
Line 664:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">start_up = proc ()
amount = 50
po: stream := stream$primary_output()
Line 674:
if i//5 = 4 then stream$putc(po, '\n') end
end
end start_up</langsyntaxhighlight>
{{out}}
<pre> 0 1 9 36 100
Line 688:
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. SUM-OF-CUBES.
 
Line 717:
IF OUT-PTR IS EQUAL TO 41,
DISPLAY OUT-LINE,
MOVE 1 TO OUT-PTR.</langsyntaxhighlight>
{{out}}
<pre> 0 1 9 36 100
Line 731:
 
=={{header|Comal}}==
<langsyntaxhighlight lang="comal">0010 ZONE 8
0020 sum:=0
0030 FOR cube:=0 TO 49 DO
Line 738:
0060 IF cube MOD 5=4 THEN PRINT
0070 ENDFOR cube
0080 END</langsyntaxhighlight>
{{out}}
<pre>0 1 9 36 100
Line 752:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub cube(n: uint32): (r: uint32) is
Line 769:
print_char(' ');
end if;
end loop;</langsyntaxhighlight>
{{out}}
<pre>0 1 9 36 100 225 441 784 1296 2025
Line 778:
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">proc nonrec cube(ulong n) ulong:
n * n * n
corp
Line 791:
if n % 5 = 4 then writeln() fi
od
corp</langsyntaxhighlight>
{{out}}
<pre> 0 1 9 36 100
Line 812:
 
{{Works with|Office 365 betas 2021}}
<langsyntaxhighlight lang="lisp">SUMNCUBES
=LAMBDA(n,
BINCOEFF(1 + n)(2) ^ 2
Line 825:
)
)
)</langsyntaxhighlight>
 
The single formula in cell B2 below defines a dynamic array which populates the whole B2:K6 grid:
Line 918:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// 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>
</lang>
{{out}}
<pre>
Line 929:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: grouping math math.functions prettyprint sequences ;
 
50 <iota> 0 [ 3 ^ + ] accumulate* 10 group simple-table.</langsyntaxhighlight>
{{out}}
<pre>
Line 946:
 
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: grouping kernel math prettyprint sequences ;
 
: triangular ( n -- m ) dup 1 + * 2/ ;
 
50 <iota> [ triangular sq ] map 10 group simple-table.</langsyntaxhighlight>
{{out}}
As above.
 
=={{header|Fermat}}==
<langsyntaxhighlight lang="fermat">c:=0
for n = 0 to 49 do
c:=c+n^3;
!(c,' ');
od;</langsyntaxhighlight>
{{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}}
<langsyntaxhighlight lang="forth">: sum-cubes ( n -- )
0 swap 0 do
i i i * * + dup 7 .r
Line 971:
 
50 sum-cubes
bye</langsyntaxhighlight>
 
{{out}}
Line 990:
{{trans|Wren}}
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,008:
}
fmt.Println()
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,021:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.List (intercalate, transpose)
import Data.List.Split (chunksOf)
import Text.Printf (printf)
Line 1,062:
let ws = maximum . fmap length <$> transpose rows
pw = printf . flip intercalate ["%", "s"] . show
in unlines $ intercalate gap . zipWith pw ws <$> rows</langsyntaxhighlight>
{{Out}}
<pre> 0 1 9 36 100 225 441 784 1296 2025
Line 1,072:
 
Or, in terms of scanl:
<langsyntaxhighlight lang="haskell">import Data.List (intercalate, scanl, transpose)
import Data.List.Split (chunksOf)
import Text.Printf (printf)
Line 1,097:
let ws = maximum . fmap length <$> transpose rows
pw = printf . flip intercalate ["%", "s"] . show
in unlines $ intercalate gap . zipWith pw ws <$> rows</langsyntaxhighlight>
{{Out}}
<pre> 0 1 9 36 100
Line 1,111:
 
=={{header|J}}==
<langsyntaxhighlight Jlang="j">10 5$+/\(i.^3:)50x</langsyntaxhighlight>
{{out}}
<pre> 0 1 9 36 100
Line 1,124:
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:<langsyntaxhighlight Jlang="j"> 0 0 1r4 1r2 1r4&p. 49
1500625</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">(() => {
"use strict";
 
Line 1,300:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre> 0 1 9 36 100
Line 1,316:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">
<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;.) | .*.*.);</langsyntaxhighlight>
'''The task'''
<syntaxhighlight lang="jq">
<lang jq>
range(0;50) | sum_of_cubes as $sum
| "\(.) => \($sum)"</langsyntaxhighlight>
{{out}}
<pre>
Line 1,346:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">cubesumstil(N = 49, s = 0) = (foreach(n -> print(lpad(s += n^3, 8), n % 10 == 9 ? "\n" : ""), 0:N))
 
cubesumstil()
</langsyntaxhighlight>{{out}}
<pre>
0 1 9 36 100 225 441 784 1296 2025
Line 1,358:
</pre>
Alternatively, and using the REPL, note that recent versions of Julia implement the accumulate function:
<langsyntaxhighlight lang="julia">
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>
</lang>
 
=={{header|MAD}}==
<langsyntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
SUM = 0
THROUGH LOOP, FOR STEP = 0, 1, STEP.GE.50
Line 1,371:
LOOP PRINT FORMAT FMT, SUM
VECTOR VALUES FMT = $I9*$
END OF PROGRAM </langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'> 0
Line 1,425:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Accumulate[Range[0, 49]^3]</langsyntaxhighlight>
{{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}}==
<langsyntaxhighlight Nimlang="nim">import strutils
 
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: ' '</langsyntaxhighlight>
 
{{out}}
Line 1,445:
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">c=0;for(n=0,49,c=c+n^3;print(c))</langsyntaxhighlight>
 
=={{header|Pascal}}==
<langsyntaxhighlight lang="pascal">program sumOfFirstNCubes(output);
const
N = 49;
Line 1,463:
writeLn(sum)
end
end.</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Sum_of_first_n_cubes
Line 1,472:
 
my $sum = 0;
printf "%10d%s", $sum += $_ ** 3, $_ % 5 == 4 && "\n" for 0 .. 49;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,489:
=={{header|Phix}}==
The commented out line is based on the Factor entry, and is clearly a much faster way to get the same results.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,505:
 
=={{header|PILOT}}==
<langsyntaxhighlight lang="pilot">C :sum=0
:n=0
:max=50
Line 1,514:
T :#n: #sum
J (n<max):*loop
E :</langsyntaxhighlight>
{{out}}
<pre style='height:50ex;'>1: 0
Line 1,568:
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Show the sums of cubes given 49.
Line 1,581:
Write the result then " " on the console without advancing.
If the counter is evenly divisible by 5, write "" on the console.
Repeat.</langsyntaxhighlight>
{{out}}
<pre>
Line 1,597:
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">cubeSum: procedure options(main);
declare (i, csum) fixed decimal(7);
csum = 0;
Line 1,605:
if mod(i,5) = 4 then put skip;
end;
end cubeSum;</langsyntaxhighlight>
{{out}}
<pre> 0 1 9 36 100
Line 1,620:
=={{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.
<langsyntaxhighlight lang="pli">100H: /* SHOW THE SUMS OF THE FIRST N CUBES, 0 <= N < 23 */
 
/* CP/M BDOS SYSTEM CALL */
Line 1,650:
END;
 
EOF</langsyntaxhighlight>
{{out}}
<pre>
Line 1,661:
===Python :: Procedural===
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="python">
def main():
fila = 0
Line 1,681:
 
if __name__ == '__main__': main()
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,702:
===Python :: Functional===
 
<langsyntaxhighlight lang="python">'''Sum of first N cubes'''
 
from math import factorial
Line 1,772:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre> 0 1 9 36 100 225 441 784 1296 2025
Line 1,783:
or, as a scanning accumulation:
 
<langsyntaxhighlight lang="python">'''Sum of first N cubes'''
 
from itertools import accumulate
Line 1,841:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre> 0 1 9 36 100
Line 1,856:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> $ "" 0
50 times
[ i^ 3 ** +
Line 1,863:
space join ] ]
drop
nest$ 65 wrap$</langsyntaxhighlight>
 
{{out}}
Line 1,876:
=={{header|R}}==
This only takes one line.
<syntaxhighlight lang ="rsplus">cumsum((0:49)^3)</langsyntaxhighlight>
{{out}}
<pre> [1] 0 1 9 36 100 225 441 784 1296 2025 3025 4356 6084 8281 11025 14400
Line 1,884:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>my @sums_of_all_cubes = [\+] ^Inf X** 3;
 
say .fmt('%7d') for @sums_of_all_cubes.head(50).batch(10);</langsyntaxhighlight>
{{out}}
<pre>
Line 1,897:
 
=={{header|Red}}==
<langsyntaxhighlight lang="rebol">Red ["Sum of cubes"]
 
sum: 0
Line 1,904:
prin pad sum 8
if i % 10 = 0 [prin newline]
]</langsyntaxhighlight>
{{out}}
<pre>
Line 1,915:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program finds and displays a number of sums of the first N cubes, where N < 50 */
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 50 /*Not specified? Then use the default.*/
Line 1,940:
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 ?</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
(Shown at five-sixth size.)
Line 1,958:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see "working..." + nl
see "Sum of first n cubes:" + nl
Line 1,978:
see "Found " + row + " cubes" + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,998:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">fn main() {
(0..50)
.scan(0, |sum, x| {
Line 2,013:
}
});
}</langsyntaxhighlight>
 
{{out}}
Line 2,030:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 2,042:
end if;
end for;
end func;</langsyntaxhighlight>
{{out}}
<pre>
Line 2,058:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">0..49 -> map { .faulhaber_sum(3) }.slices(5).each { .join(' ').say }</langsyntaxhighlight>
{{out}}
<pre>
Line 2,074:
 
=={{header|Wren}}==
<langsyntaxhighlight lang="ecmascript">import "/fmt" for Fmt
 
System.print("Cumulative sums of the first 50 cubes:")
Line 2,083:
if ((n % 10) == 9) System.print()
}
System.print()</langsyntaxhighlight>
 
{{out}}
Line 2,096:
 
=={{header|X86 Assembly}}==
<langsyntaxhighlight lang="asm"> 1 ;Assemble with: tasm, tlink /t
2 0000 .model tiny
3 0000 .code
Line 2,154:
57 0156 C3 ret
58
59 end start</langsyntaxhighlight>
 
{{out}}
Line 2,171:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">int N, S;
[S:= 0;
for N:= 0 to 49 do
Line 2,179:
if rem(N/5) = 4 then CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
Line 2,196:
 
=={{header|Zig}}==
<langsyntaxhighlight lang="zig">pub fn main() !void {
const stdout = @import("std").io.getStdOut().writer();
Line 2,207:
if (i % 5 == 4) try stdout.print("\n", .{});
}
}</langsyntaxhighlight>
{{out}}
<pre> 0 1 9 36 100
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.