program _lucky_numbs var longint fo text Function DigSum integer byte

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
program _lucky_numbs;
var
i : longint;
fo : text;
Function DigSum(N : integer):byte;
{возвращает сумму цифр N }
var
sum : byte;
begin
sum:=0;
while N>0 do
begin
inc(sum,N mod 10);
N:=N div 10;
end;
DigSum:=sum;
end;
BEGIN
assign(fo,'output.txt');rewrite(fo);
Writeln(fo,'Lucky numbs: ');
for i:=1000 to 9999 do
if digSum(i mod 100)=DigSum(i div 100) then Writeln(fo,i);
close(fo);
END.