var n,i,k,d: integer; b: boolean;
begin
write('n = '); readln(n);
for i: =1 to n do
b: =true;
k: =i;
while b and (k> 0) do
d: =k mod 10;
if d< > 0 then b: =b and (i mod d = 0) else b: =false;
k: =k div 10;
end;
if b then write(i,' ');
writeln;
end.
пример:
n = 25
1 2 3 4 5 6 7 8 9 11 12 15 22 24
var n,i,k,d: integer; b: boolean;
begin
write('n = '); readln(n);
for i: =1 to n do
begin
b: =true;
k: =i;
while b and (k> 0) do
begin
d: =k mod 10;
if d< > 0 then b: =b and (i mod d = 0) else b: =false;
k: =k div 10;
end;
if b then write(i,' ');
end;
writeln;
end.
пример:
n = 25
1 2 3 4 5 6 7 8 9 11 12 15 22 24