Largest proper divisor of n: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 708: Line 708:
27 41 1 42 17 43 29 44 1 45
27 41 1 42 17 43 29 44 1 45
13 46 31 47 19 48 1 49 33 50</pre>
13 46 31 47 19 48 1 49 33 50</pre>

=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}


<syntaxhighlight lang="Delphi">
function FindProperDivisor(N: Integer): integer;
{Find the highest proper divisor}
{i.e. The highest number that evenly divides in N}
begin
if N=1 then Result:=1
else for Result:=N-1 downto 1 do
if (N mod Result)=0 then break;
end;



procedure AllProperDivisors(Memo: TMemo);
{Show all proper divisors for number 1..100}
var I: integer;
var S: string;
begin
S:='';
for I:=1 to 100 do
begin
S:=S+Format('%3d',[FindProperDivisor(I)]);
if (I mod 10)=0 then S:=S+#$0D#$0A;
end;
Memo.Text:=S;
end;


</syntaxhighlight>
{{out}}
<pre>
1 1 1 2 1 3 1 4 3 5
1 6 1 7 5 8 1 9 1 10
7 11 1 12 5 13 9 14 1 15
1 16 11 17 7 18 1 19 13 20
1 21 1 22 15 23 1 24 7 25
17 26 1 27 11 28 19 29 1 30
1 31 21 32 13 33 1 34 23 35
1 36 1 37 25 38 11 39 1 40
27 41 1 42 17 43 29 44 1 45
13 46 31 47 19 48 1 49 33 50
</pre>



=={{header|Draco}}==
=={{header|Draco}}==