Sum of divisors: Difference between revisions

Add Cowgol
(Add MAD)
(Add Cowgol)
Line 412:
{{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|Cowgol}}==
<lang cowgol>include "cowgol.coh";
 
const MAXIMUM := 100;
typedef N is int(0, MAXIMUM+1);
 
sub print_col(n: N, colsize: uint8) is
var buf: uint8[32];
var nsize := UIToA(n as uint32, 10, &buf[0]) - &buf[0];
while colsize > nsize as uint8 loop
print_char(' ');
colsize := colsize - 1;
end loop;
print(&buf[0]);
end sub;
 
var divsum: N[MAXIMUM+1];
var i: N := 1;
 
while i <= MAXIMUM loop
divsum[i] := 1;
i := i + 1;
end loop;
 
i := 2;
while i <= MAXIMUM loop
var j := i;
while j <= MAXIMUM loop
divsum[j] := divsum[j] + i;
j := j + i;
end loop;
i := i + 1;
end loop;
 
var col: uint8 := 0;
i := 1;
while i <= MAXIMUM loop
print_col(divsum[i], 5);
col := col + 1;
if col == 10 then
print_nl();
col := 0;
end if;
i := i + 1;
end loop;</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|F_Sharp|F#}}==
Line 427 ⟶ 484:
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|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
2,094

edits