Sum of divisors: Difference between revisions

Add CLU
(→‎{{header|Perl}}: prepend =={{header|Pascal}}==)
(Add CLU)
Line 401:
112 168 128 144 120 252 98 171 156 217
</pre>
 
=={{header|CLU}}==
<lang clu>% Calculate sum of divisors of positive integers up to and including N
div_sums = proc (n: int) returns (array[int])
% Every number is at least divisible by 1
ds: array[int] := array[int]$fill(1, n, 1)
for i: int in int$from_to(2, n) do
for j: int in int$from_to_by(i, n, i) do
ds[j] := ds[j] + i % every multiple of i is divisible by i
end
end
return (ds)
end div_sums
 
% Print sum of divisors from 1 to 100
start_up = proc ()
po: stream := stream$primary_output()
col: int := 0
for i: int in array[int]$elements(div_sums(100)) do
stream$putright(po, int$unparse(i), 5)
col := col + 1
if col // 10 = 0 then stream$putc(po, '\n') end
end
end start_up</lang>
{{out}}
<pre> 1 3 4 7 6 12 8 15 13 18
12 28 14 24 24 31 18 39 20 42
32 36 24 60 31 42 40 56 30 72
32 63 48 54 48 91 38 60 56 90
42 96 44 84 78 72 48 124 57 93
72 98 54 120 72 120 80 90 60 168
62 96 104 127 84 144 68 126 96 144
72 195 74 114 124 140 96 168 80 186
121 126 84 224 108 132 120 180 90 234
112 168 128 144 120 252 98 171 156 217</pre>
 
=={{header|Common Lisp}}==
2,114

edits