Программа:
program dividers;
var x, i, p: integer;
y: array of integer;
function dividersOf(n: integer; includeNegative: boolean := false):array of integer;
var a: array of integer;
i, k: integer;
begin
k:= 1;
if(n<0) then n:= n*(-1);
for i:= 1 to n
do if(n mod i = 0)
then begin
SetLength(a, k);
a[a.Length-1]:= i;
k:= k+1;
end;
if(includeNegative)
then a:= a.Select(x -> x*(-1)).Sorted.ToArray+a;
dividersOf:= a;
readln(x);
y:= dividersOf(x, true);
p:= y.Length-2;
i:= 0;
writeln('Делители числа ', x, ':');
repeat
write(y[i], ', ');
i:= i+1;
until i=p;
write(y[p+1], '.');
end.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Программа:
program dividers;
var x, i, p: integer;
y: array of integer;
function dividersOf(n: integer; includeNegative: boolean := false):array of integer;
var a: array of integer;
i, k: integer;
begin
k:= 1;
if(n<0) then n:= n*(-1);
for i:= 1 to n
do if(n mod i = 0)
then begin
SetLength(a, k);
a[a.Length-1]:= i;
k:= k+1;
end;
if(includeNegative)
then a:= a.Select(x -> x*(-1)).Sorted.ToArray+a;
dividersOf:= a;
end;
begin
readln(x);
y:= dividersOf(x, true);
p:= y.Length-2;
i:= 0;
writeln('Делители числа ', x, ':');
repeat
write(y[i], ', ');
i:= i+1;
until i=p;
write(y[p+1], '.');
end.