Var n,i:integer; function f(a:integer):boolean; var k,m:integer; b:boolean; begin b:=true; k:=a; while k>0 do begin m:=k mod 10; if (m=0)or(a mod m <> 0) then b:=false; k:=k div 10; end; f:=b; end; begin write('n = '); readln(n); for i:=1 to n do if f(i) then write(i,' '); end.
function f(a:integer):boolean;
var k,m:integer; b:boolean;
begin
b:=true;
k:=a;
while k>0 do
begin
m:=k mod 10;
if (m=0)or(a mod m <> 0) then b:=false;
k:=k div 10;
end;
f:=b;
end;
begin
write('n = ');
readln(n);
for i:=1 to n do
if f(i) then write(i,' ');
end.
Пример:
n = 40
1 2 3 4 5 6 7 8 9 11 12 15 22 24 33 36