Var n,i,k:integer; begin write('n = '); readln(n); k:=0; case n of 3..9 : k:=1; 10..99 : begin k:=1; for i:=10 to n do if (i mod 10 = 3)or(i div 10 = 3) then k:=k+1; end; 100..999:begin k:=1; for i:=10 to 99 do if (i mod 10 = 3)or(i div 10 = 3) then k:=k+1; for i:=100 to n do if (i div 100=3)or(i div 10 mod 10=3)or(i mod 10=3) then k:=k+1; end; end; writeln('k = ',k); end.
begin
write('n = ');
readln(n);
k:=0;
case n of
3..9 : k:=1;
10..99 : begin
k:=1;
for i:=10 to n do
if (i mod 10 = 3)or(i div 10 = 3) then k:=k+1;
end;
100..999:begin
k:=1;
for i:=10 to 99 do
if (i mod 10 = 3)or(i div 10 = 3) then k:=k+1;
for i:=100 to n do
if (i div 100=3)or(i div 10 mod 10=3)or(i mod 10=3) then k:=k+1;
end;
end;
writeln('k = ',k);
end.
Пример:
n = 120
k = 21